MarkX is a tool for converting the XML representation of the AST of parsed Markdown input generated by CommonMark to a test file used in the Markdown package.
It consists of a library - MarkXLibrary, that performs this conversion and a command-line tool - MarkXConsole, that uses this library.
- Clone this repository.
- Install any missing third-party libraries (listed below).
- .NET 6.0
- Change the current working directory to
MarkXConsole
. - Create an XML file named
input.xml
. - Navigate to the online CommonMark parser tool.
- Input any Markdown, such as
*a*
. - Navigate to the AST tab located above the window on the right.
- Copy the generated XML in full.
- Paste the XML into the file
input.xml
. - Run the command
dotnet run -- parse -f -I input.xml -O output.txt
. - See the output in the file
output.txt
.
MarkX uses the Command Line Parser Library to parse command-line arguments. Two verbs are defined, each with its own set of allowed options. However, both verbs also share a common set of options.
Parses the tests within the input files into the output file.
-
-O <file>, --output <file>
: defines an output file or a directory name with the option-t
enabled -
-t, --tree
: parses the tests into a directory tree -
-f, --file
: writes the result of parsing into a single file if the input is a single valid test -
-i, --full-index
: prefixes a name of an output file with the name of its section -
-x, --include-example
: includes example numbers in tests
Checks tests in input files against the provided result file.
-
-R <file>, --result <file>
: specifies a result file -
-r, --own-result
: makes the tests prioritise their expected result over the single provided one
-
-I <file> [<file>...], --input <file> [<file>...]
: defines input files and directories with top-level input files for parsing -
-e [<extension>...], --extensions [<extension>...]
: enables listed extensions -
-u, --ungroup-sections
: processes the tests as a single array of tests, ignoring the sections -
-c, --code-indented
: overwrites the defaultcode_block
rendering from fenced code to an indented code -
-s, --isolate-sections
: prevents identically named sections in different files from being merged -
-m, --exclude-markdown
: excludes the Markdown input from the generated result -
-q, --quiet
: suppresses printing results to console
The input consists of one or more input files or directories containing input files. An input file may either be in an XML or a JSON format.
- XML - a single test
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document SYSTEM "CommonMark.dtd">
<document xmlns="http://commonmark.org/xml/1.0">
<paragraph>
<emph>
<text>a</text>
</emph>
</paragraph>
</document>
- JSON - an array of sections with tests
[
{
"name": "test",
"tests": [
{
"markdown": "*a*\n",
"xml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n\n<document xmlns=\"http://commonmark.org/xml/1.0\">\n\t<paragraph>\n\t\t<emph>\n\t\t\t<text>a</text>\n\t\t</emph>\n\t</paragraph>\n</document>",
"example": 0
}
]
}
]
The only required property is xml
.
The output files are only produced with the option parse
, and they can take several forms:
-
Test result/file
-
Test result
documentBegin emphasis: a documentEnd
-
Test file
<<< *a* >>> documentBegin emphasis: a documentEnd
-
-
JSON (default) - new property
output
-
Directory tree - files grouped in section directories
This section shows various examples of using the parse
and check
verbs. Input and output file arguments in angle brackets represent the paths to the respective files or directories.
-
parse
-
JSON to JSON
parse -I <JSON_file> -O <JSON_file>
-
JSON to a directory tree
parse -t -I <JSON_file> -O <directory>
-
XML file with the
code_block
rendering overwrittenparse -cf -I <XML_file> -O <test_file>
-
directory of top-level XML files to a directory tree
parse -t -I <directory> -O <directory>
-
-
check
-
JSON with results included
check -I <JSON_file>
-
XML file against a single result
check -I <XML_file> -R <test_file>
-
XML file against a single result with the
line_blocks
extension enabledcheck -e line_blocks -I <XML_file> -R <test_file>
-
directory of top-level XML files against a single result
check -I <directory> -R <test_file>
-