1
0
mirror of https://github.com/danog/blackfriday.git synced 2024-12-02 09:27:49 +01:00
Commit Graph

558 Commits

Author SHA1 Message Date
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
52676fb005 Merge pull request #314 from Ambrevar/v2consttype
v2: Add missing type to TableAlignment* constants
2016-10-09 10:26:09 +03:00
Pierre Neidhardt
627dc87cad Add missing type to TableAlignment* constants 2016-10-09 08:43:40 +05:30
Vytautas Šaltenis
2b483a8555 Merge pull request #310 from Ambrevar/v2FixWalkNoContainer
v2: Fix walk with non-container root nodes
2016-10-08 18:24:09 +03:00
Vytautas Šaltenis
c60ee1aab0 Avoid allocating []byte for every written newline
This shaves off another ~25% of allocs.
2016-10-08 18:17:00 +03:00
Vytautas Šaltenis
461803619b Simplify escapeHTML and uncomment it's benchmark
Simplify and optimize escapeHTML as per @Ambrevar's suggestion: lean on
the fact that we're dealing with bytes: declare a 256-element array with
most of it filled with zeros, except for the few slots that need
escaping. This avoids some conditionals in a tight loop.

Also, uncomment it's benchmark.
2016-10-08 18:02:28 +03:00
Pierre Neidhardt
14a0c487b8 Fix walk with non-container root nodes
When passed a non-container root node, the former algorithm would go on
walking down the rest of the tree beyond the root.

The former walk fix was supposed to do that but somehow the code
disappeared in the process.
2016-10-05 11:04:51 +05:30
Vytautas Šaltenis
6141d5fde1 Merge pull request #306 from russross/v2-add-links-to-footnotes
V2 add links to footnotes
2016-10-03 08:14:53 +03:00
Vytautas Šaltenis
1aa82c4039 Make golint happy: fix method receiver
golint insists on uniform receiver names.
2016-09-17 19:36:55 +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
64d8e9ed79 Merge pull request #300 from Ambrevar/rmLaTeX
v2: Remove the LaTeX renderer stub and point to Ambrevar's implementation
2016-09-12 19:57:33 +03:00
Vytautas Šaltenis
d9ffdb7464 Use bytes.IndexByte to skip til EOL 2016-09-10 15:24:45 +03:00
Vytautas Šaltenis
993325d13f Roll our own implementation of HTML escaper 2016-09-10 14:33:37 +03:00
Pierre Neidhardt
4688db5f6f Remove the LaTeX renderer stub and point to Ambrevar's implementation 2016-09-10 16:17:05 +05:30
Vytautas Šaltenis
31f2685bfe Remove lots of string literals
Using strings in helper functions causes a lot of string-to-[]byte
allocations. This fix is centered around converging the tag() helper
func to the []byte lingo. In order to do that, a lot of string literals
have moved to global variables, where string to []byte conversion can
happen once.
2016-09-10 13:17:42 +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
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
Vytautas Šaltenis
da06641438 Add Go 1.{6,7}, stop building on ancient versions 2016-09-10 11:46:22 +03:00
Vytautas Šaltenis
b91b5719eb Merge pull request #302 from russross/v2-move-footnotest-to-html
v2: move footnotes to html
2016-09-10 11:32:03 +03:00
Vytautas Šaltenis
0a029cbe51 v2: Run the reference benchmark on Travis (#304)
* Run the reference benchmark on Travis

So that we could have a historic record of performance.
2016-09-05 19:52:01 +03:00
Vytautas Šaltenis
91753e8bc7 v2: Extract package level documentation to doc.go (#303)
* Extract package level documentation to doc.go

Plus elaborate the documentation a bit.

* Fix grammar
2016-09-05 10:25:10 +03:00
Vytautas Šaltenis
d36199c417 Rename firstPass -> preprocess 2016-09-03 15:32:37 +03:00
Vytautas Šaltenis
3c2cb1ff45 Fix typo 2016-09-03 15:29:28 +03:00
Vytautas Šaltenis
43ba539936 Add some documentation to reference struct 2016-09-03 13:16:41 +03:00
Vytautas Šaltenis
6947216efb Move footnote rendering to the renderer
Clean up footnotes part of an AST: don't force HTML-specific pieces
there, just keep a clean list of footnotes. Since some renderers might
want to process footnotes differently, let them know about footnotes by
having a flag on that list.
2016-09-03 12:39:16 +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
Vytautas Šaltenis
efa77da18b Fix omission in list item flags
When parseRefsToAST constructs a list of footnotes, it hardcoded the
item flags to ListTypeOrdered and omitted ListItemBeginningOfList.

However, a quick look around indicates that ListItemBeginningOfList
might have lost its meaning altogether in v2 (it used to control item
spacing in v1, which is now extracted from the AST structure). So add a
TODO to clean that up one day.
2016-08-29 00:16:22 +03:00
Vytautas Šaltenis
771cf410c8 Get rid of secondPass function
Most of its body was redundant, as it was moved to parseRefsToAST. After
removal of that code, only a single line remains, so move it out to the
caller of secondPass.
2016-08-29 00:16:22 +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
Vytautas Šaltenis
576065633d Merge pull request #299 from Ambrevar/v2lint
html.go: Lint RenderNode()
2016-08-12 09:13:22 +03:00
Pierre Neidhardt
225250ddf1 html.go: Lint RenderNode() 2016-08-12 09:16:14 +05:30
Vytautas Šaltenis
9926922c0b Merge pull request #295 from Ambrevar/v2FactorSmarty
v2: Factor Smartypants to HTML
2016-08-10 23:01:58 +03:00
Vytautas Šaltenis
9bff4103a3 Merge pull request #293 from Ambrevar/v2ExportFuncs
v2: Export tree manipulation functions
2016-08-10 09:21:33 +03:00
Pierre Neidhardt
02da1dfe9d Factor Smartypants to HTML
Smartypants is HTML-specific.
There is no need to run Smartypants from `Render()`.
This simplifies extensions built upon the HTML renderer.
2016-08-10 09:58:33 +05:30
Pierre Neidhardt
fdbedcdb78 Export tree manipulation functions 2016-08-10 08:59:15 +05:30
Vytautas Šaltenis
37141d5b5a Merge pull request #296 from Ambrevar/v2icon
v2: Add Icon parameter to the HTML renderer
2016-08-09 22:22:31 +03:00
Vytautas Šaltenis
c9f76b530b Merge pull request #294 from Ambrevar/v2TOC2Renderer
v2: Move TOC generation to the HTML Renderer
2016-08-09 22:06:04 +03:00
Pierre Neidhardt
413328d30b Add Icon parameter to the HTML renderer 2016-08-09 17:54:34 +05:30
Pierre Neidhardt
925d99bc55 Add TOC generation tests 2016-08-09 15:11:40 +05:30
Pierre Neidhardt
b5ff8e0286 Break lines properly in TOC generation and omit content if required 2016-08-09 15:11:40 +05:30
Pierre Neidhardt
4d756003cd Move TOC generation to the HTML Renderer 2016-08-09 12:37:44 +05:30
Vytautas Šaltenis
0f3eafddfa Merge pull request #287 from Ambrevar/v2walkfix
v2: Fix walk so that it does not step outside the root node
2016-08-05 09:17:14 +03:00
Pierre Neidhardt
ff2d79c2cb Fix walk so that it does not step outside the root node
When passed a non-container root node, or when the visitor whould return
SkipChildren for the root node, the former algorithm would go on walking
down the rest of the tree beyond the root.

This commit also removes unneeded functions and variables.
2016-08-03 15:06:49 +05:30
Vytautas Šaltenis
2e23e31bd4 Fix typo 2016-08-01 20:52:17 +03:00
Vytautas Šaltenis
bb31c53390 Merge pull request #286 from russross/add-benchmark
Repeat a run of reference tests under benchmark
2016-07-31 10:22:15 +03:00
Vytautas Šaltenis
3fe4ad2966 Enable common extensions for benchmark
Also, reset the timer after loading test data.
2016-07-30 21:40:13 +03:00
Vytautas Šaltenis
c61b63f42c Repeat a run of reference tests under benchmark
Will help with optimizing later on.
2016-07-29 18:56:08 +03:00
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
ca4bf013e8 Merge pull request #284 from russross/fix-lint
Fix most of lint errors on v2
2016-07-28 19:45:39 +03:00