From 39d6b337e63e2e0e01256aa45adb169713b83eab Mon Sep 17 00:00:00 2001 From: patarapolw Date: Fri, 23 Aug 2019 08:27:40 +0700 Subject: [PATCH] correct links --- package-lock.json | 5 ++++ package.json | 1 + public/index.html | 1 + public/posts/2019/08/句子1.1.md | 2 +- public/posts/2019/08/句子1.2.md | 2 +- public/posts/2019/08/句子1.3.md | 2 +- public/posts/2019/08/身体1.pug | 2 +- src/plugins/gtag.ts | 2 +- src/plugins/render.js | 23 +++-------------- src/plugins/showdown-ext.js | 44 +++++++++++++++++++++++++++++++++ 10 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 src/plugins/showdown-ext.js diff --git a/package-lock.json b/package-lock.json index 04bd63e..d2a5518 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6305,6 +6305,11 @@ "repeating": "^2.0.0" } }, + "indented-filter": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/indented-filter/-/indented-filter-0.1.0.tgz", + "integrity": "sha512-usPQg1fmF5JOAjg3VKHrhd7gcXaN4PuCIeyLf88/AnxZIAhys9ruuPwB2ww40eHKcz72+mMSg7Z/GVO2V5WXHQ==" + }, "indexes-of": { "version": "1.0.1", "resolved": "https://registry.npm.taobao.org/indexes-of/download/indexes-of-1.0.1.tgz", diff --git a/package.json b/package.json index a22542f..ebe58a3 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "gray-matter": "^4.0.2", "hyperpug": "^0.1.7", "hyperscript": "^2.0.2", + "indented-filter": "^0.1.0", "js-yaml": "^3.13.1", "moment": "^2.24.0", "showdown": "^1.9.0", diff --git a/public/index.html b/public/index.html index c233f19..90afdd1 100644 --- a/public/index.html +++ b/public/index.html @@ -18,6 +18,7 @@
+ diff --git a/public/posts/2019/08/句子1.1.md b/public/posts/2019/08/句子1.1.md index 8889b75..a088e71 100644 --- a/public/posts/2019/08/句子1.1.md +++ b/public/posts/2019/08/句子1.1.md @@ -8,6 +8,6 @@ tag: ### Sentence quiz -Please see [`slide:github:patarapolw/zhdiary/slides/句子1.1.md`](slide:github:patarapolw/zhdiary/slides/句子1.1.md) +Please see ^^slide(github="patarapolw/zh-slides") slides/句子1.1.md Highlight text and press "x" inside the presentation to speak. diff --git a/public/posts/2019/08/句子1.2.md b/public/posts/2019/08/句子1.2.md index 163cee8..203fa5b 100644 --- a/public/posts/2019/08/句子1.2.md +++ b/public/posts/2019/08/句子1.2.md @@ -8,6 +8,6 @@ tag: ### Sentence quiz -Please see [`slide:github:patarapolw/zhdiary/slides/句子1.2.md`](slide:github:patarapolw/zhdiary/slides/句子1.2.md) +Please see ^^slide(github="patarapolw/zh-slides") slides/句子1.2.md Highlight text and press "x" inside the presentation to speak. diff --git a/public/posts/2019/08/句子1.3.md b/public/posts/2019/08/句子1.3.md index 83d1cf0..9862886 100644 --- a/public/posts/2019/08/句子1.3.md +++ b/public/posts/2019/08/句子1.3.md @@ -8,6 +8,6 @@ tag: ### Sentence quiz -Please see [`slide:github:patarapolw/zhdiary/slides/句子1.3.md`](slide:github:patarapolw/zhdiary/slides/句子1.3.md) +Please see ^^slide(github="patarapolw/zh-slides") slides/句子1.3.md Highlight text and press "x" inside the presentation to speak. diff --git a/public/posts/2019/08/身体1.pug b/public/posts/2019/08/身体1.pug index cba5d18..1066150 100644 --- a/public/posts/2019/08/身体1.pug +++ b/public/posts/2019/08/身体1.pug @@ -11,7 +11,7 @@ tag: ### Sentence quiz - Please see [`slide:github:patarapolw/zhdiary/slides/身体1.md`](slide:github:patarapolw/zhdiary/slides/身体1.md) + Please see ^^slide(github="patarapolw/zh-slides") slides/身体1.md Highlight text and press "x" inside the presentation to speak. diff --git a/src/plugins/gtag.ts b/src/plugins/gtag.ts index 221cf2b..69d1a5f 100644 --- a/src/plugins/gtag.ts +++ b/src/plugins/gtag.ts @@ -10,7 +10,7 @@ async function gAnalytics(id: string) { s.setAttribute('data-timestamp', new Date().toISOString()); (d.head || d.body).appendChild(s); - (window as any).dataLayer = dataLayer || []; + (window as any).dataLayer = (window as any).dataLayer || []; function gtag(...x: any[]){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', id); diff --git a/src/plugins/render.js b/src/plugins/render.js index c5e205f..caf8c21 100644 --- a/src/plugins/render.js +++ b/src/plugins/render.js @@ -1,30 +1,13 @@ import showdown from "showdown"; -import h from "hyperscript"; +import { slideExt, simpleTableExt } from "./showdown-ext"; export class Markdown { constructor() { this.converter = new showdown.Converter({ - parseImgDimensions: true + parseImgDimensions: true, + extensions: [simpleTableExt, slideExt] }); this.converter.setFlavor("github"); - this.converter.addExtension({ - type: "lang", - filter(text) { - const rowRegex = /(?:(?:^|\r?\n)(?:\| )?(?:(?:.* \| )+.+)*(?:.* \| )+.+(?: \|)?(?:$|\r?\n))+/m; - - text = text.replace(rowRegex, (p0) => { - return h("table.table", p0.trim().split("\n").map((pi) => { - pi = pi.trim().replace(/^|/, "").replace(/|$/, "") - - return h("tr", pi.split(" | ").map((x) => x.trim()).map((qi) => { - return h("td", qi); - })) - })).outerHTML; - }); - - return text; - } - }) } md2html(md) { diff --git a/src/plugins/showdown-ext.js b/src/plugins/showdown-ext.js new file mode 100644 index 0000000..42c09ba --- /dev/null +++ b/src/plugins/showdown-ext.js @@ -0,0 +1,44 @@ +import { createIndentedFilter } from "indented-filter"; +import h from "hyperscript"; + +export const simpleTableExt = { + type: "lang", + filter(text) { + const rowRegex = /(?:(?:^|\r?\n)(?:\| )?(?:(?:.* \| )+.+)*(?:.* \| )+.+(?: \|)?(?:$|\r?\n))+/m; + + text = text.replace(rowRegex, (p0) => { + return h("table.table", p0.trim().split("\n").map((pi) => { + pi = pi.trim().replace(/^|/, "").replace(/|$/, "") + + return h("tr", pi.split(" | ").map((x) => x.trim()).map((qi) => { + return h("td", qi); + })) + })).outerHTML; + }); + + return text; + } +}; + +export const slideExt = { + type: "lang", + filter: createIndentedFilter("^^slide", (s, attrs) => { + const a = document.createElement("a"); + const url = new URL("https://reveal-md.herokuapp.com/"); + let q = ""; + if (attrs.github) { + q = `https://raw.githubusercontent.com/${attrs.github}/master/${s}`; + a.innerText = `github::${attrs.github}::${s}`; + } else { + q = s; + a.innerText = s; + } + + url.searchParams.append("q", q); + a.href = url.href; + a.alt = s; + a.target = "_blank"; + + return a.outerHTML; + }) +} \ No newline at end of file