mirror of
https://github.com/wassname/template.git
synced 2026-06-30 08:28:19 +08:00
Normalizes indents within code blocks
This commit is contained in:
+23
-11
@@ -1,17 +1,29 @@
|
||||
import Prism from "prismjs";
|
||||
|
||||
export default function(dom, data) {
|
||||
let codeElements = [].slice.call(dom.querySelectorAll("code"));
|
||||
let codeElements = [].slice.call(dom.querySelectorAll("dt-code"));
|
||||
codeElements.forEach(el => {
|
||||
// let content = el.innerHTML;
|
||||
// el.innerHTML = "";
|
||||
// let p = dom.createElement("pre");
|
||||
// let c = dom.createElement("code");
|
||||
// console.log(content)
|
||||
let highlighted = Prism.highlightElement(el);
|
||||
// c.innerHTML = highlighted;
|
||||
// p.appendChild(c);
|
||||
// el.appendChild(p);
|
||||
|
||||
let content = el.textContent;
|
||||
el.innerHTML = "";
|
||||
let language = el.getAttribute("language");
|
||||
let c = dom.createElement("code");
|
||||
if (el.getAttribute("block") === "") {
|
||||
// Let's normalize the tab indents
|
||||
content = content.replace(/\n/, "");
|
||||
let tabs = content.match(/\s*/);
|
||||
content = content.replace(new RegExp("\n" + tabs, "g"), "\n");
|
||||
content = content.trim();
|
||||
let p = dom.createElement("pre");
|
||||
p.appendChild(c);
|
||||
el.appendChild(p);
|
||||
} else {
|
||||
el.appendChild(c);
|
||||
}
|
||||
let highlighted = content;
|
||||
if (Prism.languages[language]) {
|
||||
c.setAttribute("class", "language-" + language);
|
||||
highlighted = Prism.highlight(content, Prism.languages[language]);
|
||||
}
|
||||
c.innerHTML = highlighted;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -176,3 +176,7 @@ dt-article figure figcaption b {
|
||||
font-weight: 600;
|
||||
color: rgba(0, 0, 0, 1.0);
|
||||
}
|
||||
|
||||
dt-article > dt-code {
|
||||
display: block;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
code[class*="language-"],
|
||||
pre[class*="language-"] {
|
||||
color: black;
|
||||
background: none;
|
||||
text-shadow: 0 1px white;
|
||||
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
|
||||
text-align: left;
|
||||
|
||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+8
-16
@@ -41,34 +41,26 @@
|
||||
<h2>Markdown</h2>
|
||||
<div>
|
||||
<div dt-markdown>Any element with a `dt-markdown` attribute will be rendered with its contents replaced with a markdown processed version. We use [marked](https://github.com/chjj/marked), with [github flavored markdown](https://help.github.com/articles/basic-writing-and-formatting-syntax/) and [smartypants](https://daringfireball.net/projects/smartypants/).</div>
|
||||
<pre><code class="language-html">
|
||||
<dt-code block language="html">
|
||||
<div dt-markdown>
|
||||
###This markdown will be rendered as HTML
|
||||
|
||||
For more about markdown, read this [tutorial](https://help.github.com/articles/basic-writing-and-formatting-syntax/).
|
||||
</div>
|
||||
|
||||
</code></pre>
|
||||
</dt-code>
|
||||
</div>
|
||||
<hr>
|
||||
<h2>Code Blocks</h2>
|
||||
<p>Syntax highlighting is provided within <code class="language-html"><code></code> tags. Just wrap the source with this: <code class="language-html"><code class="language-html">let x = 10;</code></code>. For larger blocks of code, add a <code class="language-html"><pre></code> tag:</p>
|
||||
<pre><code class="language-html">
|
||||
<pre><code class="language-javascript">
|
||||
<p>Syntax highlighting is provided within <dt-code language="html"><dt-code></dt-code> tags. An example of inline code snippets: <dt-code language="html"><dt-code language="html">let x = 10;</dt-code></dt-code>. For larger blocks of code, add a <dt-code>block</dt-code> attribute:</p>
|
||||
<dt-code block language="html">
|
||||
<dt-code block language="javascript">
|
||||
var x = 25;
|
||||
function(x){
|
||||
return x * x;
|
||||
}
|
||||
</code></pre>
|
||||
</code></pre>
|
||||
<p>You can also use code blocks within markdown blocks. For instance: </p>
|
||||
<pre><code class="language-html">
|
||||
<div dt-markdown>
|
||||
```javascript
|
||||
let x = 25;
|
||||
```
|
||||
</div>
|
||||
</code></pre>
|
||||
</dt-code>
|
||||
</dt-code>
|
||||
<hr>
|
||||
<h2>Citation</h2>
|
||||
<p>Bibtex is the supported way of making academic citations. You first need have a global definition of all your possible citations. This can either be inlined in the document, or it can reference an external bibtex file.</p>
|
||||
@@ -92,7 +84,7 @@
|
||||
}
|
||||
</dt-bibliography>
|
||||
</code></pre>
|
||||
<p>Citations are then used with the <code class="language-html"><dt-cite></code> tag.</p>
|
||||
<p>Citations are then used with the <dt-code language="html"><dt-cite></dt-code> tag.</p>
|
||||
<pre><code class="language-html">
|
||||
<dt-cite>gregor2015draw</dt-cite>
|
||||
</code></pre>
|
||||
|
||||
Reference in New Issue
Block a user