Skip to content

Commit

Permalink
fix leading spaces in noformat/code macros
Browse files Browse the repository at this point in the history
  • Loading branch information
denco committed Nov 10, 2023
1 parent fd5c142 commit dd36b4a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/markupParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ export function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
let listArr: string[] = [];

for (const entry of sourceText.split(/\r?\n|\r/gi)) {
let tag = entry.trim(); //remove leading and trailing spaces
let tag = entry

if (!codeTagFlag) {
tag = tag.trim(); //remove leading and trailing spaces
}

let html_tag = false;

if ((tag.length === 0)
Expand All @@ -72,7 +77,7 @@ export function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
}

if (!codeTagFlag) {
tag = tag.replace(/h(\d+)\.\s([^\n]+)/g, "<h$1>$2</h$1>");
tag = tag.replace(/h(\d+)\.\s([^\r?\n]+)/g, "<h$1>$2</h$1>");

// tag = tag.replace(/_([^_]*)_/g, "<em>$1</em>");
tag = tag.replace(/\+([^+]*)\+/g, "<u>$1</u>");
Expand Down Expand Up @@ -407,11 +412,10 @@ export function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {

if (!tag.match(/<\/?code|<\/?pre>|<\/?table>|<\/?t[r|d|h]|<\/?li|<\/?ul|<\/?ol|<\/?div/) && !codeTagFlag) {
tag = `<div>${tag}</div>`;
} else if (codeTagFlag && tag.indexOf('>') < 0) {
tag = tag + '\n';
} else if (codeTagFlag && tag.indexOf('<') < 0) {
tag = `${tag}\n`;
}
result += `${tag}`;
}

return result;
}
9 changes: 7 additions & 2 deletions src/test/suite/fixtures/expected/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ <h2><strong>code:</strong></h2>
</div>
<div class="code-block">
<span class="code-title">test</span>
<pre><code style='font-family: Menlo, Monaco, Consolas, monospace'>&lt;test>&lt;test1 />&lt;/test></code></pre>
<pre><code style='font-family: Menlo, Monaco, Consolas, monospace'>&lt;test>
&lt;test1 />
&lt;/test>
</code></pre>
</div>
<div class="code-block">
<span class="code-title">title</span>
Expand All @@ -219,6 +222,8 @@ <h2><strong>code:</strong></h2>
<h2><strong>noformat:</strong></h2>
</div>
<div class="code-block">
<pre><code style='font-family: Menlo, Monaco, Consolas, monospace'>&lt;xml>&lt;/xml></code></pre>
<pre><code style='font-family: Menlo, Monaco, Consolas, monospace'>&lt;xml>
&lt;/xml>
</code></pre>
</div>
<pre><code style='font-family: Menlo, Monaco, Consolas, monospace'>noformat &lt;tag>&lt;/tag> oneline</code></pre>

0 comments on commit dd36b4a

Please sign in to comment.