Commit Graph

93 Commits (4ca8c28b21a883c59eb518036a3fe45a3f281463)

Author SHA1 Message Date
Bjørn Erik Pedersen 4ca8c28b21 Add Smartypants support for French Guillemets
This commits adds flag `HTML_SMARTYPANTS_QUOTES_NBSP` which, when combined with `HTML_USE_SMARTYPANTS` will insert non-breaking spaces between the double quotes and the contained text.

This is mostly relevant for use in French  with `HTML_SMARTYPANTS_ANGLED_QUOTES`.

It should not hurt existing code path in the performance department:

```
name                     old time/op    new time/op    delta
SmartDoubleQuotes-4    2.58µs ± 1%    2.58µs ± 1%   ~             (p=1.000 n=5+5)

name                     old alloc/op   new alloc/op   delta
SmartDoubleQuotes-4    5.27kB ± 0%    5.27kB ± 0%   ~     (all samples are equal)

name                     old allocs/op  new allocs/op  delta
SmartDoubleQuotes-4      13.0 ± 0%      13.0 ± 0%   ~     (all samples are equal)
```

Fixes #378
2017-07-27 22:08:20 +02:00
choueric a20399916c fix duplicate and recursive footnotes. (#241)
Fix the infinite loop when there is a self-refer footnote by checking if
the reference is already added into parser.notes.

It also fixes of creating duplicate footnotes through this modification.

Add coresponding testcase.
2017-06-08 14:43:56 +08:00
Dmitri Shuralyov 96537c6eaa Create a place for document-level unit tests.
These will be helpful for catching regressions or changes in behavior
to edge cases such as empty input, or specifically crafted inputs that
may cause panics, etc.

Move test for issue #172 there since it's a document-level test, not an
inline one.

Add test for issue #173.

Make some things more consistent.

Don't use a named receiver in methods that don't use it. This makes the
code more readable since one can more quickly tell the inputs to the
method.
2016-07-15 14:59:57 -04:00
Tom Kwok 69f51afe42 Add test for issue 172 2016-04-03 21:08:32 +08:00
Vytautas Šaltenis d18b67ae0a Add more tests for emphasised text
Including EXTENSION_NO_INTRA_EMPHASIS. These nail down a fix for #178
that was a side effect of cc3cc10.
2015-12-12 19:18:59 +02:00
Vytautas Šaltenis fc740701cf Cosmetics: fix comment placement and import order 2015-12-10 21:03:21 +02:00
Vytautas Šaltenis bcd6dd8711 Don't require the input to end with a newline
Technically, not ending a line with a newline is wrong, but this blunder
is so pervasive that we have no other choice but to live with it.

Fixes #180.
2015-12-10 20:52:47 +02:00
Nat Welch 45f5800b75 Get tests to pass 2015-11-29 00:08:48 +00:00
Nat Welch 1622f8f312 Apply @miekg's patch
From 99ce7134f6.patch
2015-11-26 22:11:25 +00:00
Vytautas Šaltenis 510be64de0 Merge pull request #216 from russross/issue-194
Fix footnote following an exclamation point
2015-11-04 21:40:57 +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 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 4b26653fe0 Fix broken test and add test for HTML_SMARTYPANTS_DASHES 2015-10-27 20:21:08 +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 c9f5708bd5 Spread out test cases for readability 2015-10-20 20:31:08 +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
Dmitri Shuralyov 18186eea26 Do not emit newline after <img> tag.
This changes HTML renderer not to always add a newline character after
<img> tags. This is desirable because <img> tags can be inlined, and
sometimes you want to avoid whitespace on left and right sides. Previous
behavior of always adding a newline would unavoidably create whitespace
after <img> tag.

Update all tests to match new behavior. There are few changes, and
they're completely isolated to inline image tests.

Fixes #169.
2015-05-25 12:59:05 -07:00
Vytautas Šaltenis 314ce8fe44 Add a missing test case for reference override
Exercise link text override.
2015-05-06 15:57:15 +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 58c4ddd431 Added test for backslash line break 2015-04-23 10:49:08 +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
Beyang Liu 60b0b4024f add rel="noreferrer" option 2015-03-14 16:46:32 -07:00
elian0211 27ba4cebef update about links
when link to current directory or parent directory
2015-02-20 17:06:55 +08:00
Anthony Fok 2c9fe2cd03 Avoid converting dates into fractions
So that dates like 1/2/2005 and 2005/3/4 stay the way it is
without turning into ½/2005 and 2005/¾.

See http://discuss.gohugo.io/t/any-way-to-disable-smart-fractions/328
for discussions.
2015-01-24 15:23:48 -07:00
KenjiTakahashi fdda8b88b0 add tests for emphasis with links 2014-12-28 06:28:15 +01: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
bep 857a1a0260 Add support for angled, double quotes
The flag `HTML_SMARTYPANTS_ANGLED_QUOTES` combined with `HTML_USE_SMARTYPANTS` configures rendering of double quotes as angled left and right quotes (&laquo; &raquo;).

The SmartyPants documentation mentions a special syntax for these, `<<>>`, a syntax neither pretty nor user friendly.

Typical use cases would be either or, or combined, but never in the same document. As an example would be a person from Norway; he has a blog in both English and Norwegian (his native tounge); he would then configure Blackfriday to use angled quotes for the Norwegian section, but keep them as reqular double quotes for the English.

If the flag `HTML_SMARTYPANTS_ANGLED_QUOTES` is not provided, everything works as before this commit.
2014-11-05 23:29:41 +01:00
Vytautas Saltenis 427a14caf2 Convert silly funcs to consts 2014-09-22 11:44:58 +03:00
Vytautas Šaltenis 3a99461662 Make sure relative URLs are preserved
Add tests to make sure we don't break relative URLs again.
Extracted common html flags and common extensions for easy access from
tests.

Closes issue #104, which was fixed as a side effect of cf6bfc9.
2014-09-21 16:29:24 +03:00
Vytautas Saltenis cf6bfc9d6d Rip off all blackfriday's html sanitization effort
As per discussion in issue #90.
2014-09-19 21:25:23 +03:00
Daniel Imfeld 5bf00efe39 Remove unnecessary HTML_ABSOLUTE_LINKS flag 2014-05-29 09:17:20 -05:00
Daniel Imfeld 4ccf982a9e Add tests for absolute prefix 2014-05-25 13:22:33 -05:00
Daniel Imfeld 2ce0592896 Add tests for new footnote functionality 2014-05-25 13:07:05 -05:00
Daniel Imfeld 628c02d37b Move footnote prefix to a better place 2014-05-24 14:28:37 -05:00
Daniel Imfeld ec41294bc4 Add footnote prefix option. Needs testing 2014-05-24 02:55:13 -05:00
Daniel Imfeld 5c12499aa1 Add ability to convert relative links to absolute 2014-05-18 01:28:15 -05:00
Martin Probst 7daa6e8b70 Move sanitization tests into their own file.
Also adds an explicit test for [link](...) syntax to be sanitized.
2014-05-03 14:37:23 +02:00
Vytautas Šaltenis 717a976f69 Merge pull request #76 from mprobst/self-closing
feat: Write self-closing tags with a />
2014-05-03 15:11:53 +03:00
Martin Probst 55d8f72dde feat: Write self-closing tags with a />
Adds tests for self-closing tags both for correct writing and for correct
sanitization, i.e. stripping attributes on them.
2014-05-03 13:59:10 +02:00
Martin Probst 11e042f6c1 Avoid raw mode parsing so that raw mode tags like <script> don't cause issues.
Certain tags like <script> but also <title> and others switch an HTML5 parser
into raw mode, which causes the rest of the HTML string to be always parsed as
text, including any elements or entities that we do want to support (e.g. <p>).

As we're going to escape any of the raw text elements anyway (it's e.g. script,
style, title, xmp, noframes, and a couple of others) we can just switch of raw
text parsing by disabling it after each starting tag.
2014-05-03 13:26:52 +02:00
Martin Probst 915f7049a0 Add a test for the correct handling of escaped entities in HTML.
The sanitization code does not retain any particular escaped entities - it
parses the HTML and thus loses the information on what entities were in the
original. The result is correct UTF-8 HTML though.
2014-05-03 12:34:16 +02:00
Martin Probst 8d2af3a21b Add support for a bunch more safe HTML element tags, and bring them into some order. 2014-05-01 22:08:32 +02:00
Vytautas Šaltenis aeb569ff46 Merge pull request #70 from mprobst/master
fix: Handle all different token types that the parser can emit (d'oh).
2014-05-01 21:59:07 +03:00
Martin Probst f9b7593e65 fix: Handle all different token types that the parser can emit (d'oh). 2014-05-01 20:55:53 +02:00