From 441796f845dc60f9f499b9f7f4889081a7be6bbe Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 21 Apr 2018 18:59:16 +0900 Subject: Add search syntax --- src/text/html.ts | 7 +++++++ src/text/parse/elements/search.ts | 13 +++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/text/parse/elements/search.ts (limited to 'src/text') diff --git a/src/text/html.ts b/src/text/html.ts index 55265c206a..f33ef4997b 100644 --- a/src/text/html.ts +++ b/src/text/html.ts @@ -75,6 +75,13 @@ const handlers = { a.href = url; a.textContent = url; document.body.appendChild(a); + }, + + search({ document }, { content, query }) { + const a = document.createElement('a'); + a.href = `https://www.google.com/?#q=${query}`; + a.textContent = content; + document.body.appendChild(a); } }; diff --git a/src/text/parse/elements/search.ts b/src/text/parse/elements/search.ts new file mode 100644 index 0000000000..12ee8ecbb8 --- /dev/null +++ b/src/text/parse/elements/search.ts @@ -0,0 +1,13 @@ +/** + * Search + */ + +module.exports = text => { + const match = text.match(/^(.+?) 検索(\n|$)/); + if (!match) return null; + return { + type: 'search', + content: match[0], + query: match[1] + }; +}; -- cgit v1.2.3-freya