Commit Graph

123 Commits

Author SHA1 Message Date
Vytautas Šaltenis fecfec2059 Implement SkipImages and add test 2016-04-05 12:48:28 +03:00
Vytautas Šaltenis 9da90c5929 Allow NodeVisitor to have some control over traversal
Make NodeVisitor return status and decide upon it which node to go to
next. So far, this allows to skip subtrees and quit early.
2016-04-05 12:48:28 +03:00
Vytautas Šaltenis 607478a8ce Implement SkipLinks, add test 2016-04-04 14:08:35 +03:00
Vytautas Šaltenis d7f18785f1 Implement TOC and OmitContents
Move these two flags from HTML renderer's flags to extensions. Implement
both since they were not yet implemented in the AST rewrite. Add tests.

Note: the expected test strings differ very slightly from v1. The HTML
produced by v2 has a few extra newlines compared to the old one, but
it's now uniform with other sections of the generated document. If the
newline placement gets cleaned up in the future, this will get fixed
automatically, since the renderer is agnostic about the TOC list.
2016-04-04 12:04:20 +03:00
Vytautas Šaltenis 0b69796248 Go style: more Html -> HTML renames 2016-04-01 15:37:21 +03:00
Vytautas Šaltenis 02a5ce37ff Go style: Html{Block|Span} -> HTML{Block|Span} 2016-04-01 13:15:47 +03:00
Vytautas Šaltenis 32802dbae5 Go style: rename Toc to TOC 2016-04-01 13:12:38 +03:00
Vytautas Šaltenis f1361aa0da Make ForEachNode func a Walk method on Node 2016-04-01 12:36:56 +03:00
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 7869a127bd Combine two Smartypants structs into one
Combine smartypantsRenderer and smartypantsData into one struct. Make
action funcs methods on that struct.
2016-03-31 21:40:37 +03:00
Vytautas Šaltenis 4a7ff562a7 Rename Html to HTML to adhere to Go style 2016-03-31 13:54:09 +03:00
Vytautas Šaltenis fd2d69de5e Make renderer write to an explicit io.Writer 2016-03-30 21:13:02 +03:00
Vytautas Šaltenis dc7d4b68df Remove some cruft 2016-03-30 15:56:53 +03:00
Vytautas Šaltenis 0382dab0c3 The single node renderer is a separate func now
A default HTML renderer for a single node is now easily accessible.
Makes it easy to fall back to the default behavior when writing custom
HTML renderers.
2016-03-30 15:48:43 +03:00
Vytautas Šaltenis 886a1405c0 Extract local funcs/vars into methods/members 2016-03-30 15:37:03 +03:00
Vytautas Šaltenis 94893247d1 Add a new renderer from AST
This is the new renderer that walks AST and renders everything to a
buffer. Completely covers all the functionality of the previous renderer
and will likely replace it.
2016-03-30 12:54:12 +03:00
Vytautas Šaltenis 7846a310ea Remove unused code 2016-03-30 12:54:12 +03:00
Vytautas Šaltenis d1b544e278 HACK: render TOC the old way, backup and truncate output 2015-11-10 21:36:32 +02: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 7a97ffe689 Remove almost all uses of 'out' in HTML renderer 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 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 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 29f02f7d01 Rename Renderer method receivers
From 'options' to 'r'. This change contains only a massive rename, no
other changes.
2015-11-10 21:08:32 +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
Anthony Fok 38cc6e9ae8 Add HTML_SMARTYPANTS_DASHES for toggling smart dashes 2015-08-03 23:57:26 -06:00
Vincent Batoufflet c4825a719d Add definition lists extension support 2015-06-03 08:03:34 +02: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 c6be4fadb1 Merge pull request #161 from rtfb/issue-146
Issue 146
2015-05-06 15:30:31 +03:00
Vytautas Šaltenis a2702e7449 Simplify isRelativeLink() a bit 2015-04-11 18:06:30 +03: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 f4655604b3 Cleanup a random bunch of repetitive loops
Replace them with helper function calls.
2015-04-07 21:59:42 +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
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
Vytautas Šaltenis 315f87d8c0 Merge pull request #128 from bjornerik/angled-quotes
Add support for angled, double quotes
2014-11-28 19:33:07 +02:00
Austin Ziegler 9c061de92b Allow configurable header ID prefix/suffixes.
This is specifically driven by the Hugo usecase where multiple documents
are often rendered into the same ultimate HTML page.

When a header ID is written to the output HTML format (either through
`HTML_TOC`, `EXTENSION_HEADER_IDS`, or `EXTENSION_AUTO_HEADER_IDS`), it
is possible that multiple documents will hvae identical header IDs. To
permit validation to pass, it is useful to have a per-document prefix or
suffix (in our case, an MD5 of the content filename, and we will be
using it as a suffix).

That is, two documents (`A` and `B`) that have the same header ID (`#
Reason {#reason}`), will end up having an actual header ID of the form
`#reason-DOCID` (e.g., `#reason-A`, `#reason-B`) with these HTML
parameters.

This is built on top of #126 (more intelligent collision detection for
`EXTENSION_AUTO_HEADER_IDS`).
2014-11-23 20:37:27 -05: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
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