Skip to content

Commit ce0da32

Browse files
committed
markdown: warn when inline html is ignored
- print warnings when block or inline html is ignored - better support for reporting location using FileLoc
1 parent 68cdea8 commit ce0da32

5 files changed

Lines changed: 23 additions & 9 deletions

File tree

src/markdown/fan/ast/Block.fan

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// 08 Oct 2024 Matthew Giannini Creation
77
//
88

9+
using util
10+
911
**
1012
** A block node.
1113
**
@@ -38,10 +40,10 @@ final class Document : Block
3840
new make() { }
3941

4042
** Get the file this document was generated from, or null if not known
41-
File? file { private set }
43+
internal FileLoc? locRef { private set }
4244

4345
** Set the file that was used to generate this document
44-
This withFile(File file) { this.file = file; return this }
46+
This withFileLoc(FileLoc? loc) { this.locRef = loc; return this }
4547
}
4648

4749
**************************************************************************

src/markdown/fan/ast/Node.fan

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ abstract class Node
5757
** Get the file location for this node from the original parsed source.
5858
** If the location is not known or source spans were not enabled during
5959
** parsing, then return `util::FileLoc.unknown`.
60-
FileLoc loc()
60+
virtual FileLoc loc()
6161
{
6262
if (sourceSpans.isEmpty) return FileLoc.unknown
63-
file := doc?.file?.name ?: "inputs"
63+
file := doc?.locRef?.file ?: "inputs"
6464
span := sourceSpans.first
6565
// I think if the best way to report the location is using the first source span
6666
return FileLoc(file, span.lineIndex+1, span.columnIndex+1)

src/markdown/fan/ext/xetodoc/Xetodoc.fan

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// 01 Nov 2024 Matthew Giannini Creation
77
//
88

9+
using util
10+
911
**
1012
** Xetodoc is a curated set of features and extensions to the CommonMark syntax.
1113
**
@@ -66,9 +68,9 @@
6668
}
6769

6870
** Convenience to render the given Xetodoc to HTML
69-
static Str toHtml(Str source, LinkResolver? linkResolver := null)
71+
static Str toHtml(Str source, LinkResolver? linkResolver := null, FileLoc? loc := null)
7072
{
71-
htmlRenderer.render(parser(linkResolver).parse(source))
73+
htmlRenderer.render(parser(linkResolver).parse(source).withFileLoc(loc))
7274
}
7375

7476
** Convenience to render the given node to HTML

src/markdown/fan/parser/Parser.fan

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// 08 Oct 2024 Matthew Giannini Creation
77
//
88

9+
using util
10+
911
**
1012
** Parse input text into a tree of nodes.
1113
**
@@ -64,7 +66,7 @@ const class Parser
6466

6567
** Convenience to parse a file into a `Document`. If source span parsing
6668
** is enabled the nodes will have access to the file location using `Node.loc`.
67-
Document parseFile(File file) { parseStream(file.in).withFile(file) }
69+
Document parseFile(File file) { parseStream(file.in).withFileLoc(FileLoc(file.pathStr)) }
6870

6971
** Convenience for 'parseStream(text.in)'
7072
Document parse(Str text) { parseStream(text.in) }

src/markdown/fan/render/html/CoreHtmlNodeRenderer.fan

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@
129129

130130
override Void visitHtmlBlock(HtmlBlock block)
131131
{
132-
if (cx.disableHtml) return
132+
if (cx.disableHtml)
133+
{
134+
echo("WARN: ignore block html ${block.loc}")
135+
return
136+
}
133137

134138
html.line
135139
if (cx.escapeHtml)
@@ -228,7 +232,11 @@
228232

229233
override Void visitHtmlInline(HtmlInline inline)
230234
{
231-
if (cx.disableHtml) return
235+
if (cx.disableHtml)
236+
{
237+
echo("WARN: ignore inline html ${inline.loc}: ${inline.literal}")
238+
return
239+
}
232240

233241
if (cx.escapeHtml)
234242
html.text(inline.literal)

0 commit comments

Comments
 (0)