Skip to content

Commit

Permalink
feat: 將 README.md 寫入 plugin.xml -> description
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Feb 12, 2022
1 parent d3eb8ad commit be62451
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 2 deletions.
76 changes: 76 additions & 0 deletions lib/md.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import MarkdownIt from 'markdown-it';
import { outputFile, readFile } from 'fs-extra';
import { join } from 'upath2';
import { __root } from '../test/__root';
import { readFileSync } from 'fs';
import Token from 'markdown-it/lib/token';
import { LazyURL } from 'lazy-url';

const baseUrl = 'https://raw.githubusercontent.com/bluelovers/idea-l10n-zht/master/';

const baseUrl2 = 'https://github.com/bluelovers/idea-l10n-zht/blob/master/';

export function createMarkdownIt()
{
const md = new MarkdownIt({
html: true,
linkify: true,
breaks: true,
xhtmlOut: true,
typographer: true,
});

md.linkify.set({
fuzzyLink: false,
});

md.core.ruler.push('baseurl', (state) =>
{
_rewriteTokens(state.tokens);
});

return md
}

export function renderMarkdown(input: string | Uint8Array)
{
const md = createMarkdownIt();

return `<meta charset="utf-8"/>` + md.render(input?.toString())
}

export function _rewriteTokens(tokens: Token[]): void
{
for (const token of tokens)
{
if (token.type === 'image')
{
for (const attr of token.attrs)
{
if (attr[0] === 'src')
{
//attr[1] = baseUrl + attr[1];
attr[1] = new LazyURL(attr[1], baseUrl).href;
break;
}
}
}
else if (token.type === 'link_open')
{
for (const attr of token.attrs)
{
if (attr[0] === 'href')
{
//attr[1] = baseUrl + attr[1];
attr[1] = new LazyURL(attr[1], baseUrl2).href;
break;
}
}
}
// Process recursively
if (token.children !== null)
{
_rewriteTokens(token.children);
}
}
}
10 changes: 9 additions & 1 deletion lib/meta.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { renderMarkdown } from './md';
import { readFileSync } from 'fs';
import { join } from 'upath2';
import { __root } from '../test/__root';

export function updateMeta(content_new: string)
{
const html = renderMarkdown(readFileSync(join(__root, 'README.md')));

return content_new
.replace(/<name>.+<\/name>/, `<name>Chinese (Traditional) Language Pack / 繁體中文語言包</name>`)
.replace(/<vendor>.+<\/vendor>/, `<vendor url="https://github.com/bluelovers/idea-l10n-zht">bluelovers</vendor><category>Language Pack</category>`)
.replace(/<description>.+<\/description>/, `<description><![CDATA[Jetbrains IntelliJ Chinese (Traditional) Language Pack / 繁體中文語言包<p>The Chinese Language Pack localizes the UI of IntelliJ IDEA, AppCode, CLion, DataGrip, GoLand, PyCharm, PhpStorm, RubyMine, and WebStorm into Chinese.</p><p>中文語言包將為您的 IntelliJ IDEA, AppCode, CLion, DataGrip, GoLand, PyCharm, PhpStorm, RubyMine, 和WebStorm 帶來中文化的界面。</p><h2>install</h2><ul><li>install from <a href="https://github.com/bluelovers/idea-l10n-zht/raw/master/plugin-dev-out/zh.jar" target="_blank">github</a> (推薦安裝此版本來得到最新版本)</li><li>install from <a href="https://plugins.jetbrains.com/plugin/18365-chinese-traditional-language-pack-----">jetbrains</a></li></ul><blockquote><p>注意:請先移除或禁用<a href="https://plugins.jetbrains.com/plugin/13710-chinese-simplified-language-pack----" target="_blank">官方簡體中文語言包</a></p></blockquote><p>歡迎來協助改善翻譯 <a href="https://github.com/bluelovers/idea-l10n-zht">https://github.com/bluelovers/idea-l10n-zht</a></p>]]></description>`)
//.replace(/<description>.+<\/description>/, `<description><![CDATA[Jetbrains IntelliJ Chinese (Traditional) Language Pack / 繁體中文語言包<p>The Chinese Language Pack localizes the UI of IntelliJ IDEA, AppCode, CLion, DataGrip, GoLand, PyCharm, PhpStorm, RubyMine, and WebStorm into Chinese.</p><p>中文語言包將為您的 IntelliJ IDEA, AppCode, CLion, DataGrip, GoLand, PyCharm, PhpStorm, RubyMine, 和WebStorm 帶來中文化的界面。</p><h2>install</h2><ul><li>install from <a href="https://github.com/bluelovers/idea-l10n-zht/raw/master/plugin-dev-out/zh.jar" target="_blank">github</a> (推薦安裝此版本來得到最新版本)</li><li>install from <a href="https://plugins.jetbrains.com/plugin/18365-chinese-traditional-language-pack-----">jetbrains</a></li></ul><blockquote><p>注意:請先移除或禁用<a href="https://plugins.jetbrains.com/plugin/13710-chinese-simplified-language-pack----" target="_blank">官方簡體中文語言包</a></p></blockquote><p>歡迎來協助改善翻譯 <a href="https://github.com/bluelovers/idea-l10n-zht">https://github.com/bluelovers/idea-l10n-zht</a></p>]]></description>`)
.replace(/<description>.+<\/description>/, `<description><![CDATA[${html}]]></description>`)
.replace(/<id>.+<\/id>/, `<id>com.intellij.zh-tw</id>`)
.replace(/<change-notes>.+<\/change-notes>/, `<change-notes><![CDATA[See <a href="https://github.com/bluelovers/idea-l10n-zht/commits/master">https://github.com/bluelovers/idea-l10n-zht/commits/master</a> or <a href="https://github.com/bluelovers/idea-l10n-zht/blob/master/CHANGELOG.md">CHANGELOG.md</a>]]></change-notes>`)
.replace(/ until-build="[^"]+"/, '')
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
"fs-extra": "^10.0.0",
"jszip": "^3.7.1",
"jszip-fixed-date": "^1.0.3",
"lazy-url": "^1.0.20",
"markdown-it": "^12.3.2",
"micromatch": "^4.0.4",
"novel-segment": "^2.7.87",
"novel-segment-cli": "^1.1.105",
Expand All @@ -112,6 +114,7 @@
"@types/conventional-changelog": "^3.1.1",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^27.4.0",
"@types/markdown-it": "^12.2.3",
"@types/micromatch": "^4.0.2",
"@types/node": "*",
"@types/node-fetch": "<3 >=2.5.12",
Expand Down
Loading

0 comments on commit be62451

Please sign in to comment.