Commit Graph

134 Commits

Author SHA1 Message Date
Vytautas Šaltenis 4ba991937b Store cell alignment in own type instead of int 2016-04-01 11:44:59 +03:00
Vytautas Šaltenis 60026cc3c6 Make ListData a nested struct instead of pointer 2016-04-01 11:21:25 +03:00
Vytautas Šaltenis 2a07386455 Rename HtmlFlags to HTMLFlags to adhere to Go style 2016-04-01 10:49:23 +03:00
Vytautas Šaltenis 71fe9a191e Remove dead code 2016-04-01 10:48:25 +03:00
Vytautas Šaltenis a55b2615a4 Run Smartypants as a separate pass over the AST
Separate Smartypants somewhat from the HTML renderer. Move its flags
from HtmlFlags to Extensions (probably should be moved to its own set of
flags, but not now). With that done, do a separate walk of the tree and
either run Smartypants processor if it's enabled, or simply escape text
nodes.
2016-04-01 10:44:22 +03:00
Vytautas Šaltenis 4c11a2a62d Expose Parse func that grabs input and returns AST 2016-03-30 19:40:10 +03:00
Vytautas Šaltenis c1011c8ab2 Remove unneeded reference to Renderer from parser 2016-03-30 19:35:53 +03:00
Vytautas Šaltenis 4d74c6a071 Make common flags and extensions public
Add DefaultOptions convenience variable.
2016-03-30 19:29:00 +03:00
Vytautas Šaltenis dc7d4b68df Remove some cruft 2016-03-30 15:56:53 +03:00
Vytautas Šaltenis 70124f1ea3 Enable full AST construction, use the new renderer
Connect the block and inline parsers. Most of the tests now pass, only a
couple fail, they need fixes in the test suite.
2016-03-30 14:47:30 +03:00
Vytautas Šaltenis eb70b23221 Construct AST WIP: add inline-level nodes
Parse the content of the block nodes for inline markdown, decorate the
tree with what's found. Tests still broken, need to connect the dots.
2016-03-30 14:38:19 +03:00
Vytautas Šaltenis 7c95b7a189 Construct AST WIP: add block-level nodes
Build a partial tree by adding block nodes. The block nodes will then be
traversed and inline markdown parsed inside each of them. Tests are
broken at this point until the full tree is constructed.
2016-03-30 12:57:12 +03:00
Vytautas Šaltenis 97235182ac Enable writing plain text straight to output
It's only used in a single place and should probably be refactored away,
but this workaround is OK for now.
2015-11-10 21:36:32 +02:00
Vytautas Šaltenis 114d6b0d68 Eradicate 'out' parameter in top level code 2015-11-10 21:36:32 +02:00
Vytautas Šaltenis 08233481ed Fix Begin/EndHeader to use the new 'out'-less interface
Remove the 'out' parameter. Also, instead of returning and passing the
position of TOC, use CopyWrites to capture contents of the header and
pass that captured buffer instead.
2015-11-10 21:36:32 +02:00
Vytautas Šaltenis dce6df90b9 Add infrastructure to collect output in a buffer
Add a structure to collect output in a buffer (replaces what used to be
the 'out' parameter all over the place).

Notable things about this struct are the captureBuff and copyBuff
buffers. They're intended to redirect all the output (captureBuff) or
make a copy of all the output (copyBuff) while they're set to non-nil.
Here's an example of their intended use:

    // what used to be a temp buffer as an 'out' parameter
    //     var cellWork bytes.Buffer
    //     p.inline(&cellWork, data[cellStart:cellEnd])
    // can now be captured like this:
    cellWork := p.r.CaptureWrites(func() {
           p.inline(data[cellStart:cellEnd])
    })
2015-11-10 21:36:32 +02:00
Vytautas Šaltenis 7ec50399c3 Remove 'out' parameter from parser funcs
This only removes the parameter from declarations, everything is broken
at the moment.
2015-11-10 21:36:32 +02:00
Vytautas Šaltenis 6e42506fcc Remove 'out' parameter from renderer interface
This only removes the parameter from func declarations, not from their
bodies, so obviously breaks everything. Will be restored in upcoming
commits.
2015-11-10 21:36:31 +02:00
Vytautas Šaltenis a78344809b Fix smartypants smart dash processing
Change the way maybeLineBreak gets called to avoid breaking up stretches
of unprocessed characters that smartypants expects.

This inline processing is getting a bit out of hand, something needs to
be done about it.
2015-11-10 21:36:31 +02:00
Vytautas Šaltenis dd01088b7a Remove last call to Truncate() from parser
Autolink detection used to be triggered by a colon and preceding
protocol name used to be rewound. Now instead of doing that, trigger
autolink processing on [hmfHMF] and see if it looks like a link.
2015-11-10 21:36:31 +02:00
Vytautas Šaltenis 8e90e8b645 Remove calls to Truncate() from linebreak parser
Replace output truncation with appropriate inline callbacks. lineBreak()
is now only responsible for handling HardLineBreak. BackslashLineBreak
is handled in escape() and trailing whitespace is considered in
maybeLineBreak().
2015-11-10 21:36:31 +02:00
Vytautas Šaltenis ef087889f4 Remove a couple calls to Truncate() from parser
Link parser used to truncate in two cases: when parsing image links and
inline footnotes. In order to avoid this truncation, introduce a
separate callback for each of these cases and avoid writing extra
characters instead of truncating them after the fact.
2015-11-10 21:36:31 +02:00
Vytautas Šaltenis bc4735b84d Remove callback from Footnotes renderer event
Split Footnotes into two events: BeginFootnotes and EndFootnotes,
removing the need for callback.
2015-11-10 21:08:32 +02:00
Vytautas Šaltenis 6d6be3d2b2 Remove callback from Paragraph renderer event
Split Paragraph into two events: BeginParagraph and EndParagraph,
removing the need for callback.
2015-11-10 21:08:32 +02:00
Vytautas Šaltenis af1b26fa04 Remove callback from List renderer event
Split List into two events: BeginList and EndList, removing the need for
callback.
2015-11-10 21:08:32 +02:00
Vytautas Šaltenis 82be6cab6d Remove callback from Header renderer event
Split Header into two events: BeginHeader and EndHeader, removing the
need for callback.
2015-11-10 21:08:32 +02:00
Vytautas Šaltenis b16c9b3787 Simplify callbacks in Renderer interface
The callbacks used to return bools, but none of the actual
implementations return false, always true. So in order to make further
refactorings simpler, make the interface reflect the inner workings: no
more return values, no more conditionals.
2015-11-10 21:08:32 +02:00
Vytautas Šaltenis ee98bc0bf4 Massive replacement of C_STYLE flags to typed ones 2015-11-10 21:08:32 +02:00
Vytautas Šaltenis 06515e9125 Rename public constants to idiomatic Go 2015-11-10 20:27:34 +02:00
Dmitri Shuralyov 0b647d0506 Use more idiomatic form for set of strings.
This is a better style for a set, since each value can only be present
or absent.

With bool as value type, each value may be absent, or true or false. It
also uses slightly more memory.
2015-11-09 21:18:55 -08:00
Vytautas Šaltenis 18432fc942 Add a few missing HTML5 block tags
Closes #197.
2015-11-08 21:34:44 +02:00
Vytautas Šaltenis f1ce82cb01 Sort block tag list alphabetically 2015-11-08 21:33:20 +02:00
Vytautas Šaltenis a58274acef Minor style fix: declare ref first in a loop 2015-11-04 21:07:39 +02:00
Vytautas Šaltenis c29209fcda Add String() method to reference struct 2015-11-02 20:24:34 +02:00
Vytautas Šaltenis 9e68ff937b Fix nested footnotes
This is both nasty and neat at the same time. All the code could handle
nested footnotes just fine, the only place that was not working was the
final loop that printed the list. The loop was in a range form, which
couldn't account for another footnote being inserted while processing
existing ones. Changing the loop to the iterative form solves that.

Closes #193.
2015-11-02 20:17:46 +02:00
Vytautas Šaltenis 660c9fd283 Add <style> tag to a list of recognized block tags
Closes #182.
2015-11-01 12:36:02 +02:00
Vytautas Šaltenis 4193e8665a Drop misleading comment and turn func into method
* The comment is no longer true.
* Other functions similar to terminateBlockquote() are methods, so make
this one a method too.
2015-11-01 09:32:30 +02:00
Vytautas Šaltenis 133788657b Refix fenced code blocks w/o preceding blank lines
Change approach at fixing #45: don't patch input markdown at preprocess
pass, instead improve special case detection when parsing paragraphs.

Leave the fenced code block detection in the preprocess pass though,
it's been put to another use since then, to suppress tab expansion
inside code blocks.
2015-10-29 20:28:16 +02:00
Vytautas Šaltenis 6712f32cfd Merge pull request #190 from anthonyfok/add-flag-for-smart-dashes
Add HTML_SMARTYPANTS_DASHES for toggling smart dashes
2015-10-27 20:08:54 +02:00
Vytautas Šaltenis 1d673b3cd9 Bump const VERSION to 1.4
This is probably not used by too many people, but there it goes anyway.

Closes #119.
2015-10-18 20:51:29 +03:00
Anthony Fok 38cc6e9ae8 Add HTML_SMARTYPANTS_DASHES for toggling smart dashes 2015-08-03 23:57:26 -06:00
Tw d28de22ef0 fix index out of range panic in reference link
Add checking before accessing the input data.

Fix #172 and #173 issues.

Signed-off-by: Tw <tw19881113@gmail.com>
2015-06-08 15:31:55 +08:00
Vincent Batoufflet c4825a719d Add definition lists extension support 2015-06-03 08:03:34 +02:00
Vytautas Šaltenis 0bf420d72a Fix a couple typos 2015-05-23 09:28:21 +03:00
Vytautas Šaltenis eeb2c39339 Merge branch 'master' of https://github.com/jtolds/blackfriday into jtolds-master
Conflicts:
	inline_test.go
2015-05-06 15:41:12 +03:00
neclepsio 68a3c498f6 Add EXTENSION_BACKSLASH_LINE_BREAK 2015-04-22 14:10:44 +02:00
Tw d90024b17b Delete unnecessary copy of input when enable fenced code extension
Copy of input waste time and memory.

Signed-off-by: Tw <tw19881113@gmail.com>
2015-02-11 15:44:24 +08:00
JT Olds 8e10236be5 support replacing [refid][] syntax link content with alternate content 2014-12-18 17:36:46 -07:00
JT Olds 5e8b222b69 Add programmable reference overrides
If a user provides a ReferenceOverride function, then reference ids
will be passed to the given ReferenceOverride function first, before
consulting the generated reference table.

The goal here is to enable programmable support for
"WikiWords"-style identifiers or other application-specific
user-generated keywords.

Example, writing documentation:

 The [Frobnosticator][] is a very important class in our codebase.
 While it is used to frobnosticate widgets in general, it can also
 be passed to the [WeeDoodler][] to interesting effect.

This might be solveable with the HTML Renderer relative prefix, but
I didn't see a good way of making a short link to 'Frobnosticator'
relatively without having to write it twice. Maybe
'<Frobnosticator>' should work? Should Autolinks work for relative
links?

In addition, I wanted a little more richness. I plan to support
Godoc links by prefixing references with a '!', like so:

  Check out the [Frobnosticator][] helper function
  [!util.Frobnosticate()][]

The first link links to the Frobnosticator architectural overview
documentation, whereas the second links to Godoc.

Better advice on how to implement this sort of think with
Blackfriday is highly desired.
2014-12-16 16:17:52 -07:00
Austin Ziegler a5e88a3350 Add a flag to turn on header ID generation.
- Fixes #51, #101, and #102.
- Uses the [code][gfm] mentioned by @shurcooL from his Github
  Flavored Markdown parser extension in a [comment on #102][comment].
  Since this was mentioned, I assumed that @shurcooL would be OK with
  this being included under the licence provided by blackfriday (there
  is no licence comment on his code).
- I’ve added it behind another flag, EXTENSION_AUTO_HEADER_IDS, that
  would need to be turned on for it to work. It works with both prefix
  and underline headers.

[gfm]: 3bec0366a8/github_flavored_markdown/main.go (L90-L102)
[comment]: https://github.com/russross/blackfriday/issues/102#issuecomment-51272260
2014-10-27 16:54:23 -04:00