Skip to content

Commit

Permalink
generate: don't move link reference definition out of block (#738)
Browse files Browse the repository at this point in the history
Closes: #737
  • Loading branch information
ee7 committed Mar 22, 2023
1 parent bbbad5c commit 3dabaff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/generate/generate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func alterHeadings(s: string, linkDefs: var seq[string], h2 = ""): string =
if s.continuesWith("#", i+1) and not (inFencedCodeBlock or
inFencedCodeBlockTildes or inCommentBlock):
result.add '#'
elif s.continuesWith("[", i+1):
elif s.continuesWith("[", i+1) and not (inFencedCodeBlock or
inFencedCodeBlockTildes or inCommentBlock):
let j = s.find("]:", i+2)
if j > i+2 and j < s.find('\n', i+2):
var line = ""
Expand Down
22 changes: 22 additions & 0 deletions tests/test_generate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ proc testGenerate =
check alterHeadings(s, linkDefs, "Maps") == "## Maps\n\n" & expected
check linkDefs.len == 0

test "alterHeadings: keeps link reference definition inside block":
const s = """
# Heading 1
~~~~exercism/note
See the [foo docs][foo-docs] for more details.
[foo-docs]: https://example.com
~~~~
""".unindent()

const expected = """
~~~~exercism/note
See the [foo docs][foo-docs] for more details.
[foo-docs]: https://example.com
~~~~""".unindent()

var linkDefs = newSeq[string]()
check alterHeadings(s, linkDefs) == expected
check linkDefs.len == 0

proc main =
testGenerate()

Expand Down

0 comments on commit 3dabaff

Please sign in to comment.