# Load a markdown file as a documentation object
fun load_markdown(filepath: String): MDoc
do
- var mdoc = new MDoc(new Location(new SourceFile.from_string(filepath, ""),0,0,0,0))
var s = new FileReader.open(filepath)
+ var lines = new Array[String]
+ var line_starts = new Array[Int]
+ var len = 1
while not s.eof do
- mdoc.content.add(s.read_line)
- end
+ var line = s.read_line
+ lines.add(line)
+ line_starts.add(len)
+ len += line.length + 1
+ end
+ s.close
+ var source = new SourceFile.from_string(filepath, lines.join("\n"))
+ source.line_starts.add_all line_starts
+ var mdoc = new MDoc(new Location(source, 1, lines.length, 0, 0))
+ mdoc.content.add_all(lines)
return mdoc
end
line_starts[0] = 0
end
- # Position of each line start
+ # Offset of each line start in the content `string`.
+ #
+ # Used for fast access to each line when rendering parts of the `string`.
var line_starts = new Array[Int]
end
-test_nitunit3/README.md: Error: there is a block of invalid Nit code, thus not considered a nitunit. To suppress this warning, enclose the block with a fence tagged `nitish` or `raw` (see `man nitdoc`). At 1,2--4: Syntax Error: unexpected malformed character '\]..
-test_nitunit3/README.md: ERROR: nitunit.test_nitunit3.<group> (in .nitunit/test_nitunit3-0.nit): Runtime error: Assert failed (.nitunit/test_nitunit3-0.nit:7)
+test_nitunit3/README.md:1,0--13,0: Error: there is a block of invalid Nit code, thus not considered a nitunit. To suppress this warning, enclose the block with a fence tagged `nitish` or `raw` (see `man nitdoc`). At 1,2--4: Syntax Error: unexpected malformed character '\]..
+test_nitunit3/README.md:1,0--13,0: ERROR: nitunit.test_nitunit3.<group> (in .nitunit/test_nitunit3-0.nit): Runtime error: Assert failed (.nitunit/test_nitunit3-0.nit:7)
DocUnits:
Entities: 2; Documented ones: 2; With nitunits: 3; Failures: 2
TestSuites:
No test cases found
Class suites: 0; Test Cases: 0; Failures: 0
-<testsuites><testsuite package="test_nitunit3"><testcase classname="nitunit.test_nitunit3" name="<group>"><failure message="test_nitunit3/README.md: Invalid block of code. At 1,2--4: Syntax Error: unexpected malformed character '\].."></failure><system-err></system-err><system-out>assert false
+<testsuites><testsuite package="test_nitunit3"><testcase classname="nitunit.test_nitunit3" name="<group>"><failure message="test_nitunit3/README.md:1,0--13,0: Invalid block of code. At 1,2--4: Syntax Error: unexpected malformed character '\].."></failure><system-err></system-err><system-out>assert false
assert true
</system-out><error message="Runtime error: Assert failed (.nitunit/test_nitunit3-0.nit:7)
"></error></testcase></testsuite><testsuite package="test_nitunit3"><testcase classname="nitunit.test_nitunit3.<module>" name="<module>"><system-err></system-err><system-out>assert true
-test_nitunit_md.md: ERROR: nitunit.<file>.test_nitunit_md.md (in .nitunit/file-0.nit): Runtime error: Assert failed (.nitunit/file-0.nit:8)
+test_nitunit_md.md:1,0--15,0: ERROR: nitunit.<file>.test_nitunit_md.md:1,0--15,0 (in .nitunit/file-0.nit): Runtime error: Assert failed (.nitunit/file-0.nit:8)
DocUnits:
Entities: 1; Documented ones: 1; With nitunits: 1; Failures: 1
TestSuites:
No test cases found
Class suites: 0; Test Cases: 0; Failures: 0
-<testsuites><testsuite package="test_nitunit_md.md"><testcase classname="nitunit.<file>" name="test_nitunit_md.md"><system-err></system-err><system-out>var a = 1
+<testsuites><testsuite package="test_nitunit_md.md:1,0--15,0"><testcase classname="nitunit.<file>" name="test_nitunit_md.md:1,0--15,0"><system-err></system-err><system-out>var a = 1
assert 1 == 1
assert false
</system-out><error message="Runtime error: Assert failed (.nitunit/file-0.nit:8)