Commit Graph

92 Commits

Author SHA1 Message Date
autopp
535ad76f61 Fix checking of backslash in link text (#510) (#511) 2019-01-20 20:36:43 +02:00
Rebecca Turner
1bb1d0171c Fixed HTML entity regex (#453)
The old regex missed a lot of HTML entities, like long references
(from 6-character entites like ≈ to the somewhat rarer
&CounterClockwiseContourIntegral;) as well as numeric references
(decimal e.g. Ӓ or hex e.g. 𓫶). This fixes that.
2018-05-24 21:32:58 +03:00
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
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
d04a53c644 Merge branch 'v2' into v2-perf-tweaks 2017-02-02 12:00:48 +02:00
Vytautas Šaltenis
ea57e93666 Several fixes after code review 2017-02-02 11:54:10 +02:00
Vytautas Saltenis
9357a8f949 Simplify inline() even more
* Move handler call inside the inner loop's 'if handler != nil' clause
* Move appender of possible tail bytes outside of loop
* Get rid of outer loop
* Rename i -> beg

Again, this does not seem to gain much performance, but makes the code
significantly more readable.
2016-10-29 11:31:21 +03:00
Vytautas Saltenis
6438ce6de8 Avoid some conditionals in inline parser
Rearrange inline parser a little bit to check less conditionals for
every byte.

* Add early check for len(data) == 0
* Move 'for i < len(data)' check inside the (rarer) positive clause of
  trigger result handling
* A check for newline turned out to be redundant
* Look up p.inlineCallback only once

All that does not gain much performance in itself, but doesn't hurt and
makes the code structure simpler, which will hopefully allow further
streamlining.
2016-10-29 10:10:22 +03:00
Vytautas Šaltenis
8a11177489 Add direct link to a footnote from it's referer
Some renderers might not care to have an explicit list of footnotes at
the end of the document, instead they're interested in the content of
the footnote at the location of a referer. Make their lives easier by
providing such a link
2016-09-17 19:35:42 +03:00
Vytautas Šaltenis
39b8ed198a Avoid general purpose ToLower in autolink detection
This is a huuuge low hanging fruit! maybeAutoLink has shrunk from ~25%
of run time to around 3%. I could stop now.
2016-09-10 12:09:32 +03:00
Pierre Neidhardt
6fd47b3b61 v2: Only split when inline callbacks consume some bytes (#301)
* Only split when inline callbacks consume some bytes

The former hacks around maybeLineBreak and Smartypants are no longer
needed.
The algorithm has been streamlined: shorter, simpler, faster.
The 'currBlock' field of the parser is gone.

* Remove spurious logs
2016-08-19 08:56:33 +03:00
Pierre Neidhardt
fdbedcdb78 Export tree manipulation functions 2016-08-10 08:59:15 +05:30
Vytautas Šaltenis
a9baf845f1 Unpublish and rename LinkType constants (#285)
* Unpublish and rename LinkType constants

The constants are only used in the parsing phase, they are not recorded
in the AST directly, so make them private. Improve their names along the
way. Fix tagLength to return two values instead of taking an output
parameter.

* autoLinkType -> autolinkType

And remove unnecessary comment.
2016-07-29 08:01:31 +03:00
Vytautas Šaltenis
cd2f079140 More lint: inline.go 2016-07-27 21:31:29 +03:00
Vytautas Šaltenis
e054c962e7 More lint: markdown.go and ripples to other files 2016-07-27 21:28:41 +03:00
Vytautas Šaltenis
c26fdef40e Move html entity regexp to where it's used
And unify regexp variable names.
2016-04-11 11:45:19 +03:00
Vytautas Šaltenis
02a5ce37ff Go style: Html{Block|Span} -> HTML{Block|Span} 2016-04-01 13:15:47 +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
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
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
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
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
ee98bc0bf4 Massive replacement of C_STYLE flags to typed ones 2015-11-10 21:08:32 +02:00
Vytautas Šaltenis
c5943e0685 Reformat a dustball of ifs into a switch statement 2015-11-04 21:32:53 +02:00
Vytautas Šaltenis
ca8c21a297 Fix footnote following an exclamation point
Link parser interpreted the sequence "![^foo]" as an image, but if
footnote extension is enabled, it's quite clear that it should be
interpreted as a footnote following something with an exclamation point
at the end.

Closes #194.
2015-11-03 20:52:36 +02:00
Vytautas Šaltenis
d4ee3ea08b Simplify return value 2015-10-28 21:21:51 +02:00
Vytautas Šaltenis
a18a46c9b9 Merge pull request #203 from russross/issue-136
Handle comments within a block
2015-10-20 20:45:00 +03:00
Vytautas Šaltenis
53982c119c Merge pull request #206 from russross/issue-164
Fix footnote followed by a reference style link
2015-10-19 09:17:51 +03:00
Vytautas Šaltenis
4b668b875b Merge pull request #205 from russross/issue-156
Fix bug parsing emphasis
2015-10-19 09:08:30 +03:00
Vytautas Šaltenis
f7510976a3 Fix escaping asterisks within emphasis
First check for escaped character, *then* look if i-th character is an
emphasis character.

Closes #18.
2015-10-13 19:57:15 +03:00
Vytautas Šaltenis
08eac30cb9 Fix footnote followed by a reference style link
When parsing a deferred footnote, we already know it's a footnote from
the '[^' part, so we can use that to hit a proper switch branch
(default) a bit later on.

Closes #164.
2015-10-12 21:18:33 +03:00
Vytautas Šaltenis
cc3cc10ef2 Fix bug parsing emphasis
Start searching for emphasis character at 0th index instead of 1st.
Fixes a corner case with doubly emphasised code span followed by
another code span on the same line.

Changes interpretation of improperly nested emphasis, hence the change
in TestEmphasisMix().

Closes #156.
2015-10-12 21:06:27 +03: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
Vytautas Šaltenis
62f0018e2f Replace snake_case with mixedCase 2015-05-06 15:55:04 +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
c1917970db Use EXTENSION_BACKSLASH_LINE_BREAK 2015-04-22 14:09:39 +02:00
neclepsio
d4c83fb4da Fix previous commit
Backslash was not removed from output.
2015-04-22 14:04:08 +02:00
neclepsio
2824a549c3 Implement backslash hard line break
See http://spec.commonmark.org/0.18/#example-527
2015-04-22 12:23:19 +02:00
Vytautas Šaltenis
b3137e7c8f Merge pull request #152 from elian0211/about_links
update about links
2015-04-09 20:41:45 +03:00
Vytautas Šaltenis
195dac9f5b Fix recognition of consecutive footnotes
The second footnote was treated as if the pair of them were a reference
style link, without checking if the second bit is another footnote.

Fixes issue 158.
2015-04-03 21:08:46 +03:00
elian0211
bd11a52f1e update func isSafeLink 2015-02-25 21:27:13 +08:00
elian0211
27ba4cebef update about links
when link to current directory or parent directory
2015-02-20 17:06:55 +08:00
KenjiTakahashi
f147218833 fix #19: return immediately from link skipping if end of emphasis is found 2014-12-29 00:34:06 +01: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