From 426b67a86043f9d1c54e5d0968761af57d32cc0b Mon Sep 17 00:00:00 2001 From: Wouter de Jong Date: Fri, 5 Mar 2021 23:26:56 +0100 Subject: [PATCH] Support documents starting with a literal block marker This fixes https://github.com/weaverryan/docs-builder/issues/36 --- lib/Parser/DocumentParser.php | 6 ++++++ tests/Functional/tests/code/code.html | 2 ++ tests/Functional/tests/code/code.rst | 4 ++++ tests/Functional/tests/code/code.tex | 5 +++++ 4 files changed, 17 insertions(+) diff --git a/lib/Parser/DocumentParser.php b/lib/Parser/DocumentParser.php index bf2cb1b9..68f12775 100644 --- a/lib/Parser/DocumentParser.php +++ b/lib/Parser/DocumentParser.php @@ -234,6 +234,12 @@ private function parseLine(string $line): bool return false; } + if (trim($line) === '::') { + $this->isCode = true; + + return true; + } + if ($this->lineChecker->isBlockLine($line)) { if ($this->isCode) { $this->setState(State::CODE); diff --git a/tests/Functional/tests/code/code.html b/tests/Functional/tests/code/code.html index 0c9e2364..3f67bb2d 100644 --- a/tests/Functional/tests/code/code.html +++ b/tests/Functional/tests/code/code.html @@ -1,3 +1,5 @@ +
This is a code block
+

Code block:

This is a code block You hou!
 
diff --git a/tests/Functional/tests/code/code.rst b/tests/Functional/tests/code/code.rst index 0ad7cea2..b04e02a0 100644 --- a/tests/Functional/tests/code/code.rst +++ b/tests/Functional/tests/code/code.rst @@ -1,3 +1,7 @@ +:: + + This is a code block + Code block:: This is a code block diff --git a/tests/Functional/tests/code/code.tex b/tests/Functional/tests/code/code.tex index b299bd01..92f65347 100644 --- a/tests/Functional/tests/code/code.tex +++ b/tests/Functional/tests/code/code.tex @@ -1,3 +1,8 @@ +\lstset{language=} +\begin{lstlisting} +This is a code block + +\end{lstlisting} Code block: \lstset{language=} \begin{lstlisting}