diff options
author | Lukas Larsson <lukas@erlang.org> | 2019-10-11 11:35:08 +0200 |
---|---|---|
committer | Lukas Larsson <lukas@erlang.org> | 2019-10-17 10:07:48 +0200 |
commit | b36ccde89c71ca282f09170a8a674b67d6f878fa (patch) | |
tree | 8c0e7dda7e8b796792cb9d5b0f0d23c6c16476bd /lib/erl_docgen | |
parent | 5e30a839258f2685fb064f3e1ec381766df94175 (diff) | |
download | erlang-b36ccde89c71ca282f09170a8a674b67d6f878fa.tar.gz |
erl_docgen: Make code type attribute influence highlight mode
Diffstat (limited to 'lib/erl_docgen')
-rw-r--r-- | lib/erl_docgen/priv/js/highlight.js | 17 | ||||
-rw-r--r-- | lib/erl_docgen/priv/xsl/db_html.xsl | 17 |
2 files changed, 23 insertions, 11 deletions
diff --git a/lib/erl_docgen/priv/js/highlight.js b/lib/erl_docgen/priv/js/highlight.js index 0594b42aa3..b176a60928 100644 --- a/lib/erl_docgen/priv/js/highlight.js +++ b/lib/erl_docgen/priv/js/highlight.js @@ -28,11 +28,22 @@ window.addEventListener("load", function () { window.clearInterval(intervalId); - var i, len, nodes = document.querySelectorAll('.example'); - for (i = 0, len = nodes.length; i < len; i += 1) { - window.hljs.highlightBlock(nodes[i]); + function highlightLanguage(css, languages) { + var i, len, nodes = document.querySelectorAll(css); + for (i = 0, len = nodes.length; i < len; i += 1) { + hljs.configure({languages: languages}); + window.hljs.highlightBlock(nodes[i]); + } } + highlightLanguage('.example-erl',["erlang"]); + highlightLanguage('.example-erl-repl',["erlang-repl"]); + highlightLanguage('.example-c',["cpp"]); + highlightLanguage('.example-cpp',["cpp"]); + highlightLanguage('.example-sh',["bash"]); + highlightLanguage('.example-diff',["diff"]); + highlightLanguage('.example-none',["erlang","erlang-repl","bash","cpp","diff"]); + } intervalId = window.setInterval(doHighlight, 50); diff --git a/lib/erl_docgen/priv/xsl/db_html.xsl b/lib/erl_docgen/priv/xsl/db_html.xsl index 18bc8cd1cf..2ce6e08f43 100644 --- a/lib/erl_docgen/priv/xsl/db_html.xsl +++ b/lib/erl_docgen/priv/xsl/db_html.xsl @@ -1226,17 +1226,18 @@ <!-- Code --> <xsl:template match="code"> <xsl:param name="chapnum"/> + <xsl:variable name="type" select="@type"/> <xsl:variable name="codenum"> <xsl:number level="any" from="chapter" count="code"/> </xsl:variable> - <xsl:choose> - <xsl:when test="not(descendant::anno)"> - <div class="example"><pre><xsl:value-of select="erl:code_trim(text())"/></pre></div> - </xsl:when> - <xsl:otherwise> - <div class="example"><pre><xsl:apply-templates/></pre></div> - </xsl:otherwise> - </xsl:choose> + <xsl:choose> + <xsl:when test="not(descendant::anno)"> + <div class="example example-{$type}"><pre><xsl:value-of select="erl:code_trim(text())"/></pre></div> + </xsl:when> + <xsl:otherwise> + <div class="example example-{$type}"><pre><xsl:apply-templates/></pre></div> + </xsl:otherwise> + </xsl:choose> </xsl:template> <!-- Pre --> |