mirror of
https://github.com/wassname/template.git
synced 2026-10-04 13:10:06 +08:00
Adding initial math support
This commit is contained in:
1 parent
c24a1d0485
commit
b3efa2526d
9 files changed
+9131
-11
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import katex from "katex";
|
||||
|
||||
const html = `
|
||||
<style>
|
||||
dt-math[block] {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
`;
|
||||
|
||||
export default function(dom, data) {
|
||||
let equationElements = [].slice.call(dom.querySelectorAll("dt-math"));
|
||||
equationElements.forEach(el => {
|
||||
let content = el.textContent;
|
||||
console.log(content)
|
||||
let displayMode = el.hasAttribute("block") ? true : false;
|
||||
el.innerHTML = html + katex.renderToString(content, {displayMode: displayMode});
|
||||
});
|
||||
}
|
||||
Whitespace-only changes.
@@ -26,6 +26,7 @@ dt-article > h4,
|
||||
dt-article > figure,
|
||||
dt-article > ul,
|
||||
dt-article > dt-byline,
|
||||
dt-article > dt-math,
|
||||
dt-article > dt-code,
|
||||
dt-article section > div,
|
||||
dt-article section > p,
|
||||
@@ -59,6 +60,7 @@ dt-article section > dt-code {
|
||||
dt-article > figure,
|
||||
dt-article > ul,
|
||||
dt-article > dt-byline,
|
||||
dt-article > dt-math,
|
||||
dt-article > dt-code,
|
||||
dt-article section > div,
|
||||
dt-article section > p,
|
||||
@@ -85,6 +87,7 @@ dt-article section > dt-code {
|
||||
dt-article > figure,
|
||||
dt-article > ul,
|
||||
dt-article > dt-byline,
|
||||
dt-article > dt-math,
|
||||
dt-article > dt-code,
|
||||
dt-article section > div,
|
||||
dt-article section > p,
|
||||
|
||||
Vendored
+9090
-10
File diff suppressed because it is too large.
Load diff
Vendored
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":null,"sources":["../components/html.js","../components/styles.js","../node_modules/js-yaml/lib/js-yaml/common.js","../node_modules/js-yaml/lib/js-yaml/exception.js","../node_modules/js-yaml/lib/js-yaml/mark.js","../node_modules/js-yaml/lib/js-yaml/type.js","../node_modules/js-yaml/lib/js-yaml/schema.js","../node_modules/js-yaml/lib/js-yaml/type/str.js","../node_modules/js-yaml/lib/js-yaml/type/seq.js","../node_modules/js-yaml/lib/js-yaml/type/map.js","../node_modules/js-yaml/lib/js-yaml/schema/failsafe.js","../node_modules/js-yaml/lib/js-yaml/type/null.js","../node_modules/js-yaml/lib/js-yaml/type/bool.js","../node_modules/js-yaml/lib/js-yaml/type/int.js","../node_modules/js-yaml/lib/js-yaml/type/float.js","../node_modules/js-yaml/lib/js-yaml/schema/json.js","../node_modules/js-yaml/lib/js-yaml/schema/core.js","../node_modules/js-yaml/lib/js-yaml/type/timestamp.js","../node_modules/js-yaml/lib/js-yaml/type/merge.js","../node_modules/js-yaml/lib/js-yaml/type/binary.js","../node_modules/js-yaml/lib/js-yaml/type/omap.js","../node_modules/js-yaml/lib/js-yaml/type/pairs.js","../node_modules/js-yaml/lib/js-yaml/type/set.js","../node_modules/js-yaml/lib/js-yaml/schema/default_safe.js","../node_modules/js-yaml/lib/js-yaml/type/js/undefined.js","../node_modules/js-yaml/lib/js-yaml/type/js/regexp.js","../node_modules/js-yaml/lib/js-yaml/type/js/function.js","../node_modules/js-yaml/lib/js-yaml/schema/default_full.js","../node_modules/js-yaml/lib/js-yaml/loader.js","../node_modules/js-yaml/lib/js-yaml/dumper.js","../node_modules/js-yaml/lib/js-yaml.js","../node_modules/js-yaml/index.js","../components/front-matter.js","../node_modules/bibtex-parse-js/bibtexParse.js","../components/bibliography.js","../node_modules/d3-time/src/interval.js","../node_modules/d3-time/src/millisecond.js","../node_modules/d3-time/src/duration.js","../node_modules/d3-time/src/second.js","../node_modules/d3-time/src/minute.js","../node_modules/d3-time/src/hour.js","../node_modules/d3-time/src/day.js","../node_modules/d3-time/src/week.js","../node_modules/d3-time/src/month.js","../node_modules/d3-time/src/year.js","../node_modules/d3-time/src/utcMinute.js","../node_modules/d3-time/src/utcHour.js","../node_modules/d3-time/src/utcDay.js","../node_modules/d3-time/src/utcWeek.js","../node_modules/d3-time/src/utcMonth.js","../node_modules/d3-time/src/utcYear.js","../node_modules/d3-time-format/src/locale.js","../node_modules/d3-time-format/src/defaultLocale.js","../node_modules/d3-time-format/src/isoFormat.js","../node_modules/d3-time-format/src/isoParse.js","../components/data.js","../../node_modules/escape-html/index.js","../components/meta.js","../components/banner.js","../node_modules/mustache/mustache.js","../components/byline.js","../components/appendix.js","../components/appendix-distill.js","../components/citation.js","../components/footnote.js","../node_modules/marked/lib/marked.js","../components/markdown.js","../node_modules/prismjs/prism.js","../components/code.js","../components/typeset.js","../components/hover-box-include.js","../components/generate-crossref.js","../components/header.js","../components/footer.js","../index.js"],"sourcesContent":["export default function(dom) {\n if (!dom.querySelector(\"html\").getAttribute(\"lang\")) {\n dom.querySelector(\"html\").setAttribute(\"lang\", \"en\")\n }\n\n let head = dom.querySelector(\"head\");\n\n if (!dom.querySelector(\"meta[charset]\")) {\n let meta = dom.createElement(\"meta\");\n meta.setAttribute(\"charset\", \"utf-8\");\n head.appendChild(meta);\n }\n if (!dom.querySelector(\"meta[name=viewport]\")) {\n let meta = dom.createElement(\"meta\");\n meta.setAttribute(\"name\", \"viewport\");\n meta.setAttribute(\"content\", \"width=device-width, initial-scale=1\");\n head.appendChild(meta);\n }\n}\n","import base from './styles-base.css';\nimport layout from './styles-layout.css';\nimport article from './styles-article.css';\nimport code from './styles-code.css';\nimport print from './styles-print.css';\n\nexport default function(dom) {\n let s = dom.createElement(\"style\");\n s.textContent = base + layout + article + code + print;\n dom.querySelector(\"head\").appendChild(s);\n}\n","'use strict';\n\n\nfunction isNothing(subject) {\n return (typeof subject === 'undefined') || (subject === null);\n}\n\n\nfunction isObject(subject) {\n return (typeof subject === 'object') && (subject !== null);\n}\n\n\nfunction toArray(sequence) {\n if (Array.isArray(sequence)) return sequence;\n else if (isNothing(sequence)) return [];\n\n return [ sequence ];\n}\n\n\nfunction extend(target, source) {\n var index, length, key, sourceKeys;\n\n if (source) {\n sourceKeys = Object.keys(source);\n\n for (index = 0, length = sourceKeys.length; index < length; index += 1) {\n key = sourceKeys[index];\n target[key] = source[key];\n }\n }\n\n return target;\n}\n\n\nfunction repeat(string, count) {\n var result = '', cycle;\nLine truncated
|
||||
{"version":3,"file":null,"sources":["../components/html.js","../components/styles.js","../node_modules/js-yaml/lib/js-yaml/common.js","../node_modules/js-yaml/lib/js-yaml/exception.js","../node_modules/js-yaml/lib/js-yaml/mark.js","../node_modules/js-yaml/lib/js-yaml/type.js","../node_modules/js-yaml/lib/js-yaml/schema.js","../node_modules/js-yaml/lib/js-yaml/type/str.js","../node_modules/js-yaml/lib/js-yaml/type/seq.js","../node_modules/js-yaml/lib/js-yaml/type/map.js","../node_modules/js-yaml/lib/js-yaml/schema/failsafe.js","../node_modules/js-yaml/lib/js-yaml/type/null.js","../node_modules/js-yaml/lib/js-yaml/type/bool.js","../node_modules/js-yaml/lib/js-yaml/type/int.js","../node_modules/js-yaml/lib/js-yaml/type/float.js","../node_modules/js-yaml/lib/js-yaml/schema/json.js","../node_modules/js-yaml/lib/js-yaml/schema/core.js","../node_modules/js-yaml/lib/js-yaml/type/timestamp.js","../node_modules/js-yaml/lib/js-yaml/type/merge.js","../node_modules/js-yaml/lib/js-yaml/type/binary.js","../node_modules/js-yaml/lib/js-yaml/type/omap.js","../node_modules/js-yaml/lib/js-yaml/type/pairs.js","../node_modules/js-yaml/lib/js-yaml/type/set.js","../node_modules/js-yaml/lib/js-yaml/schema/default_safe.js","../node_modules/js-yaml/lib/js-yaml/type/js/undefined.js","../node_modules/js-yaml/lib/js-yaml/type/js/regexp.js","../node_modules/js-yaml/lib/js-yaml/type/js/function.js","../node_modules/js-yaml/lib/js-yaml/schema/default_full.js","../node_modules/js-yaml/lib/js-yaml/loader.js","../node_modules/js-yaml/lib/js-yaml/dumper.js","../node_modules/js-yaml/lib/js-yaml.js","../node_modules/js-yaml/index.js","../components/front-matter.js","../node_modules/bibtex-parse-js/bibtexParse.js","../components/bibliography.js","../node_modules/d3-time/src/interval.js","../node_modules/d3-time/src/millisecond.js","../node_modules/d3-time/src/duration.js","../node_modules/d3-time/src/second.js","../node_modules/d3-time/src/minute.js","../node_modules/d3-time/src/hour.js","../node_modules/d3-time/src/day.js","../node_modules/d3-time/src/week.js","../node_modules/d3-time/src/month.js","../node_modules/d3-time/src/year.js","../node_modules/d3-time/src/utcMinute.js","../node_modules/d3-time/src/utcHour.js","../node_modules/d3-time/src/utcDay.js","../node_modules/d3-time/src/utcWeek.js","../node_modules/d3-time/src/utcMonth.js","../node_modules/d3-time/src/utcYear.js","../node_modules/d3-time-format/src/locale.js","../node_modules/d3-time-format/src/defaultLocale.js","../node_modules/d3-time-format/src/isoFormat.js","../node_modules/d3-time-format/src/isoParse.js","../components/data.js","../../node_modules/escape-html/index.js","../components/meta.js","../components/banner.js","../node_modules/mustache/mustache.js","../components/byline.js","../components/appendix.js","../components/appendix-distill.js","../components/citation.js","../components/footnote.js","../node_modules/katex/src/ParseError.js","../node_modules/katex/src/Settings.js","../node_modules/katex/src/unicodeRegexes.js","../node_modules/katex/src/fontMetricsData.js","../node_modules/katex/src/fontMetrics.js","../node_modules/katex/src/Style.js","../node_modules/katex/src/utils.js","../node_modules/katex/src/domTree.js","../node_modules/katex/src/symbols.js","../node_modules/katex/src/buildCommon.js","../node_modules/katex/src/delimiter.js","../node_modules/katex/src/buildHTML.js","../node_modules/katex/src/mathMLTree.js","../node_modules/katex/src/buildMathML.js","../node_modules/katex/src/Options.js","../node_modules/katex/src/buildTree.js","../node_modules/katex/src/parseData.js","../node_modules/katex/src/functions.js","../node_modules/katex/src/environments.js","../node_modules/match-at/lib/matchAt.js","../node_modules/katex/src/Lexer.js","../node_modules/katex/src/MacroExpander.js","../node_modules/katex/src/Parser.js","../node_modules/katex/src/parseTree.js","../node_modules/katex/katex.js","../components/dt-math.js","../node_modules/marked/lib/marked.js","../components/markdown.js","../node_modules/prismjs/prism.js","../components/code.js","../components/typeset.js","../components/hover-box-include.js","../components/generate-crossref.js","../components/header.js","../components/footer.js","../index.js"],"sourcesContent":["export default function(dom) {\n if (!dom.querySelector(\"html\").getAttribute(\"lang\")) {\n dom.querySelector(\"html\").setAttribute(\"lang\", \"en\")\n }\n\n let head = dom.querySelector(\"head\");\n\n if (!dom.querySelector(\"meta[charset]\")) {\n let meta = dom.createElement(\"meta\");\n meta.setAttribute(\"charset\", \"utf-8\");\n head.appendChild(meta);\n }\n if (!dom.querySelector(\"meta[name=viewport]\")) {\n let meta = dom.createElement(\"meta\");\n meta.setAttribute(\"name\", \"viewport\");\n meta.setAttribute(\"content\", \"width=device-width, initial-scale=1\");\n head.appendChild(meta);\n }\n}\n","import base from './styles-base.css';\nimport layout from './styles-layout.css';\nimport article from 'Line truncated
|
||||
@@ -1,6 +1,9 @@
|
||||
<!doctype html>
|
||||
<meta charset="utf8">
|
||||
<script src="../dist/template.js"></script>
|
||||
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css" integrity="sha384-wITovz90syo1dJWVh32uuETPVEtGigN07tkttEqPv+uR2SE/mbQcG7ATL28aI9H0" crossorigin="anonymous">
|
||||
|
||||
<script type="text/front-matter">
|
||||
title: Article Title
|
||||
published: Jan 10, 2017
|
||||
@@ -21,6 +24,8 @@
|
||||
<p>Test a long — dash -- here it is.</p>
|
||||
<p>Test for owner's possessive.</p>
|
||||
<p>Test for "quoting a passage." And another sentence. Or two.</p>
|
||||
<p>Here's a test of an inline equation <dt-math>c = a^2 + b^2</dt-math>.</p>
|
||||
<dt-math block>c = \pm\sqrt{a^2 + b^2}</dt-math>
|
||||
<p>We can also cite <dt-cite key="gregor2015draw,mercier2011humans"></dt-cite> external publications. <dt-cite key="dong2014image,dumoulin2016guide,mordvintsev2015inceptionism"></dt-cite></p>
|
||||
<p>We should also be testing footnotes<dt-fn>This will become a hoverable footnote.</dt-fn>.</p>
|
||||
</dt-article>
|
||||
|
||||
@@ -10,6 +10,7 @@ import appendix from "./components/appendix";
|
||||
import appendixDistill from "./components/appendix-distill";
|
||||
import citation from "./components/citation";
|
||||
import footnote from "./components/footnote";
|
||||
import DTMath from "./components/dt-math";
|
||||
import markdown from "./components/markdown";
|
||||
import code from "./components/code";
|
||||
import typeset from "./components/typeset";
|
||||
@@ -31,6 +32,7 @@ function renderOnLoad(dom, data) {
|
||||
byline(dom, data);
|
||||
appendix(dom, data);
|
||||
markdown(dom, data);
|
||||
DTMath(dom, data);
|
||||
code(dom, data);
|
||||
citation(dom, data);
|
||||
footnote(dom, data);
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
"commander": "^2.9.0",
|
||||
"d3-time-format": "^2.0.3",
|
||||
"html-escape": "^2.0.0",
|
||||
"katex": "^0.7.1",
|
||||
"mustache": "^2.3.0"
|
||||
}
|
||||
}
|
||||
@@ -813,6 +813,12 @@ jsprim@^1.2.2:
|
||||
json-schema "0.2.3"
|
||||
verror "1.3.6"
|
||||
|
||||
katex@^0.7.1:
|
||||
version "0.7.1"
|
||||
resolved "https://registry.yarnpkg.com/katex/-/katex-0.7.1.tgz#06bb5298efad05e1e7228035ba8e1591f3061b8f"
|
||||
dependencies:
|
||||
match-at "^0.1.0"
|
||||
|
||||
kind-of@^3.0.2:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.1.0.tgz#475d698a5e49ff5e53d14e3e732429dc8bf4cf47"
|
||||
@@ -909,6 +915,10 @@ marked@^0.3.6:
|
||||
version "0.3.6"
|
||||
resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.6.tgz#b2c6c618fccece4ef86c4fc6cb8a7cbf5aeda8d7"
|
||||
|
||||
match-at@^0.1.0:
|
||||
version "0.1.0"
|
||||
resolved "https://registry.yarnpkg.com/match-at/-/match-at-0.1.0.tgz#f561e7709ff9a105b85cc62c6b8ee7c15bf24f31"
|
||||
|
||||
micromatch@^2.1.5:
|
||||
version "2.3.11"
|
||||
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565"
|
||||
|
||||
Reference in new issue
Block a user