Commit Graph

95 Commits

Author SHA1 Message Date
Pierre Neidhardt
2501229ba6 Rename Markdown()->Run() and Processor->Markdown 2017-06-05 21:42:05 +01:00
Pierre Neidhardt
3cc9341a19 Merge Parser into Processor 2017-05-29 10:52:11 +02:00
Vytautas Šaltenis
41159b3874 Fix bad merge 2017-02-14 21:58:46 +02:00
Vytautas Šaltenis
a8c45a7349 Merge branch 'v2' into v2-functional-opts 2017-02-14 21:51:06 +02:00
Vytautas Šaltenis
747587a52d Fix all headings wrongly referred to as headers
I've left test cases alone since can't lean on the compiler for
crosschecking there.

Fixes #330.
2017-02-12 19:05:30 +02:00
Vytautas Šaltenis
e81d1d1138 Change the public interface to use functional options
Convert the most important Blackfriday's function, Markdown(), to accept
functional options (as per this Dave Cheney's post:
https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis)
2017-02-02 16:57:25 +02:00
Vytautas Šaltenis
ea57e93666 Several fixes after code review 2017-02-02 11:54:10 +02:00
Vytautas Šaltenis
120bb2fae1 Get rid of the preprocess stage
Yay!!
2016-11-10 21:49:58 +02:00
Vytautas Šaltenis
d9ffdb7464 Use bytes.IndexByte to skip til EOL 2016-09-10 15:24:45 +03:00
Vytautas Šaltenis
e0fc1a0cb1 Don't bother removing trailing newlines in code blocks
The code that collects the block bytes has already removed the trialing
newlines, so this heavyweight regexp machinery is actually doing
nothing.
2016-09-10 12:21:53 +03:00
Vytautas Šaltenis
ea8dfc4880 Move reference extraction to paragraph parser
Move reference and footnote extraction code from firstPass to a
paragraph block parser. This makes firstPass a little bit slimmer, ergo
closer to elimination.
2016-09-03 11:32:41 +03:00
Pierre Neidhardt
fdbedcdb78 Export tree manipulation functions 2016-08-10 08:59:15 +05:30
Vytautas Šaltenis
6d7f5e1bca More lint: block.go 2016-07-27 21:40:45 +03:00
Vytautas Šaltenis
cd2f079140 More lint: inline.go 2016-07-27 21:31:29 +03:00
Dmitri Shuralyov
2560c5f148 Fix issue in fenced code block pre-processing.
Forwardport changes from #280.

Fixes #279.
2016-07-15 17:03:02 -04:00
Vytautas Šaltenis
3575453f08 Move a couple helpers to parser where they're used 2016-04-11 15:55:50 +03:00
Vytautas Šaltenis
c9ea588e6f Convert uint32 fields to ints
The former is a bit too inconvenient despite being more accurate.
2016-04-11 11:15:15 +03:00
Vytautas Šaltenis
02a5ce37ff Go style: Html{Block|Span} -> HTML{Block|Span} 2016-04-01 13:15:47 +03:00
Vytautas Šaltenis
4ba991937b Store cell alignment in own type instead of int 2016-04-01 11:44:59 +03:00
Vytautas Šaltenis
c8eb73377e Fix typos 2016-04-01 11:22:13 +03:00
Vytautas Šaltenis
60026cc3c6 Make ListData a nested struct instead of pointer 2016-04-01 11:21:25 +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
f8378658c0 Fix rendering of tables
Add proper capture groups to fix the order of bits and pieces.
2015-11-10 21:36:32 +02:00
Vytautas Šaltenis
91771dc3ef Redirect output to a capture buffer where necessary
Use CaptureWrites where output should go to a temp buffer instead of the
final output.
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
352ffdefa4 Remove a bunch of 'out' parameters from calls, WIP
Still not all of them, still broken.
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
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
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
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
15eb452ae4 Fix fenced code processing inside blockquotes
Add a call to fenced code block processor inside the loop that's
responsible for collecting the quoted lines. Grok all the fenced code
block as a part of the quoted text.

Closes #122.
2015-10-29 20:28:29 +02:00
Vytautas Šaltenis
607f2ceb8a Move complex conditional to a helper func 2015-10-29 20:28:29 +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
5d3d5c198e Handle comments within a block
Added test cases both for inline and block workflows.

Closes #136.
2015-10-11 11:14:34 +03:00
Vincent Batoufflet
081aa9c378 Fix definition lists end-of-list detection 2015-06-07 09:36:53 +02: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
f4655604b3 Cleanup a random bunch of repetitive loops
Replace them with helper function calls.
2015-04-07 21:59:42 +03:00
Vytautas Šaltenis
36787eca3a Allow heading to end with \#
The problem was in a loop that skipped the optional closing hashes in a
heading like this:

    ### This is an H3 ###

Now it checks to see if a hash is escaped and if it is, treats it as a
rightmost character of the heading text, like this:

    ### This is an H3 #\##   ==>   ### This is an H3 ##

Fixes issue #146.
2015-04-07 21:58:29 +03: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
Dmitri Shuralyov
54a323aafb Update import path of sanitized_anchor_name.
It has moved into a smaller standalone repo.
Closes #139.
2015-01-10 18:23:29 -08:00
Dmitri Shuralyov
f4bb968b5f Minor cleanup.
Apply gofmt on html.go.
Apply goimports-compatible formatting on block.go (space between standard and third party imports).
Move Travis build status image in a more pleasing, common location.
Remove "Markdown pretty-printer output engine" from TODO steps; this is already done in markdownfmt.
Remove unneeded trailing whitespace in README.
2014-11-29 20:41:11 -08:00
Austin Ziegler
40f28ee022 Prevent generated header collisions, less naively.
> This is a rework of an earlier version of this code.

The automatic header ID generation code submitted in #125 has a subtle
bug where it will use the same ID for multiple headers with identical
text. In the case below, all the headers are rendered a `<h1
id="header">Header</h1>`.

  ```markdown
  # Header
  # Header
  # Header
  # Header
  ```

This change is a simple but robust approach that uses an incrementing
counter and pre-checking to prevent header collision. (The above would
be rendered as `header`, `header-1`, `header-2`, and `header-3`.) In
more complex cases, it will append a new counter suffix (`-1`), like so:

  ```markdown
  # Header
  # Header 1
  # Header
  # Header
  ```

This will generate `header`, `header-1`, `header-1-1`, and `header-1-2`.

This code has two additional changes over the prior version:

1.  Rather than reimplementing @shurcooL’s anchor sanitization code, I
    have imported it as from
    `github.com/shurcooL/go/github_flavored_markdown/sanitized_anchor_name`.

2.  The markdown block parser is now only interested in *generating* a
    sanitized anchor name, not with ensuring its uniqueness. That code
    has been moved to the HTML renderer. This means that if the HTML
    renderer is modified to identify all unique headers prior to
    rendering, the hackish nature of the collision detection can be
    eliminated.
2014-11-23 20:35:43 -05: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
Brian Goff
539b27a624 Add titleblock support 2014-08-04 14:08:22 -04:00
Vytautas Šaltenis
c5ece173ad Merge pull request #59 from johnsto/master
Header ID specifiers
2014-04-11 21:31:27 +03:00