diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-02-04 19:44:23 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-02-04 19:44:23 +0000 |
| commit | e1dff535b2a9f59c852c2d9cbe2cecb28768cdec (patch) | |
| tree | f831ccfeb19a0e01a8b1b81a9c8cfac364e057d9 /lib | |
| parent | 6189b03ede982d4ee19e8972dc134f7f708aa8fc (diff) | |
Handle anchors properly for links
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/writers/markdown-writer.js | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/writers/markdown-writer.js b/lib/writers/markdown-writer.js index 9bafc98..ff2d4b4 100644 --- a/lib/writers/markdown-writer.js +++ b/lib/writers/markdown-writer.js @@ -26,6 +26,8 @@ function markdownLink() { this.close = function() { return "](" + (href || "") + ")"; }; + + this.anchorPosition = "before"; } function markdownImage() { @@ -109,8 +111,15 @@ function markdownWriter() { function open(tagName, attributes) { attributes = attributes || {}; - + + var idHasBeenWritten = false; + if (htmlmarkdown[tagName]) { + if (htmlmarkdown[tagName].anchorPosition === "before") { + writeAnchor(attributes); + idHasBeenWritten = true; + } + if (tagName === "li") { attributes.indent = list.indent; attributes.type = list.type; @@ -129,7 +138,12 @@ function markdownWriter() { list.count = 0; } } - + if (!idHasBeenWritten) { + writeAnchor(attributes); + } + } + + function writeAnchor(attributes) { if (attributes.id) { fragments.push('<a id="' + attributes.id + '"></a>'); } |
