You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2020/06/18 03:06:58 UTC
[incubator-echarts-doc] branch live-example updated: example: fix
code may be breaked by the marked parser
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch live-example
in repository https://gitbox.apache.org/repos/asf/incubator-echarts-doc.git
The following commit(s) were added to refs/heads/live-example by this push:
new 9835d71 example: fix code may be breaked by the marked parser
9835d71 is described below
commit 9835d71b2506b5c631068dbe4c0be938a93bc2ae
Author: pissang <bm...@gmail.com>
AuthorDate: Thu Jun 18 11:06:35 2020 +0800
example: fix code may be breaked by the marked parser
---
package-lock.json | 3 +-
package.json | 1 -
tool/md2json.js | 33 +++++++++++++++----
zh/option/component/axis-common.md | 2 ++
zh/option/component/radius-axis.md | 67 ++++++++++++++++++++++++++++++++++++++
5 files changed, 97 insertions(+), 9 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index 18e0a81..b93edf2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4431,7 +4431,8 @@
"html-entities": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/html-entities/-/html-entities-1.3.1.tgz",
- "integrity": "sha512-rhE/4Z3hIhzHAUKbW8jVcCyuT5oJCXXqhN/6mXXVCpzTmvJnoH2HL/bt3EZ6p55jbFJBeAe1ZNpL5BugLujxNA=="
+ "integrity": "sha512-rhE/4Z3hIhzHAUKbW8jVcCyuT5oJCXXqhN/6mXXVCpzTmvJnoH2HL/bt3EZ6p55jbFJBeAe1ZNpL5BugLujxNA==",
+ "dev": true
},
"htmlparser2": {
"version": "4.1.0",
diff --git a/package.json b/package.json
index d81a152..8e579ed 100644
--- a/package.json
+++ b/package.json
@@ -53,7 +53,6 @@
"codemirror": "^5.54.0",
"element-ui": "^2.13.2",
"highlight.js": "^9.18.1",
- "html-entities": "^1.3.1",
"js-beautify": "^1.11.0",
"jsonpack": "^1.1.5",
"lodash.debounce": "^4.0.8",
diff --git a/tool/md2json.js b/tool/md2json.js
index bcc0052..34f508b 100644
--- a/tool/md2json.js
+++ b/tool/md2json.js
@@ -3,8 +3,6 @@ const marked = require('marked');
const etpl = require('etpl');
const glob = require('glob');
const htmlparser2 = require('htmlparser2');
-const Entities = require('html-entities').AllHtmlEntities;
-const entities = new Entities();
function convert(opts, cb) {
const mdPath = opts.path;
@@ -214,17 +212,20 @@ function mdToJsonSchema(mdStr, maxDepth, imagePath) {
properties[name] = property;
}
- function parseUIControl(html, property) {
+ function parseUIControl(html, property, codeMap) {
let currentExampleCode;
let out = '';
const parser = new htmlparser2.Parser({
onopentag(tagName, attrib) {
if (tagName === 'examplebaseoption') {
- currentExampleCode = attrib;
+ currentExampleCode = Object.assign({
+ code: ''
+ }, attrib);
}
else if (tagName.startsWith('exampleuicontrol')) {
const type = tagName.replace('exampleuicontrol', '').toLowerCase();
- if (['boolean', 'color', 'number', 'vector', 'enum', 'angle', 'percent', 'percentvector'].indexOf(type) < 0) {
+ if (['boolean', 'color', 'number', 'vector', 'enum', 'angle', 'percent', 'percentvector', 'text']
+ .indexOf(type) < 0) {
console.error(`Unkown ExampleUIControl Type ${type}`);
}
property.uiControl = {
@@ -243,7 +244,11 @@ function mdToJsonSchema(mdStr, maxDepth, imagePath) {
},
ontext(data) {
if (currentExampleCode) {
- currentExampleCode.code += entities.decode(data);
+ // Get code from map;
+ if (!codeMap[data]) {
+ throw new Error('Can\'t find code.', codeMap, data);
+ }
+ currentExampleCode.code = codeMap[data];
}
else {
out += data;
@@ -261,6 +266,7 @@ function mdToJsonSchema(mdStr, maxDepth, imagePath) {
}
}
});
+
parser.write(html);
parser.end();
@@ -334,8 +340,21 @@ function mdToJsonSchema(mdStr, maxDepth, imagePath) {
return iframe.join('');
});
+ const codeMap = {};
+ const codeKeyPrefx = 'example_base_option_code_';
+ let codeIndex= 0;
+ // Convert the code the a simple key.
+ // Avoid marked converting the markers in the code unexpectly.
+ // Like convert * to em.
+ // Also no need to decode entity
+ section = section.replace(/(<\s*ExampleBaseOption[^>]*>)([\s\S]*?)(<\s*\/ExampleBaseOption\s*>)/g, function (text, openTag, code, closeTag) {
+ const codeKey = codeKeyPrefx + (codeIndex++);
+ codeMap[codeKey] = code;
+ return openTag + codeKey + closeTag
+ });
+
renderer.html = function (html) {
- return parseUIControl(html, property);
+ return parseUIControl(html, property, codeMap);
};
property.description = marked(section, {
diff --git a/zh/option/component/axis-common.md b/zh/option/component/axis-common.md
index 7b675cd..87ad2e4 100644
--- a/zh/option/component/axis-common.md
+++ b/zh/option/component/axis-common.md
@@ -418,6 +418,8 @@ splitLine: {
<!-- Overwrite color -->
##${prefix} color(Color)
+<ExampleUIControlColor />
+
坐标轴名称的颜色,默认取 [axisLine.lineStyle.color](~${componentType}.axisLine.lineStyle.color)。
diff --git a/zh/option/component/radius-axis.md b/zh/option/component/radius-axis.md
index 841356e..ea9e466 100644
--- a/zh/option/component/radius-axis.md
+++ b/zh/option/component/radius-axis.md
@@ -5,6 +5,73 @@
极坐标系的径向轴。
+<ExampleBaseOption name="two-number-axis" title="双数值轴">
+const data = [];
+
+for (let i = 0; i <= 360; i++) {
+ const t = i / 180 * Math.PI;
+ const r = Math.sin(2 * t) * Math.cos(2 * t);
+ data.push([r, i]);
+}
+
+const option = {
+ polar: {
+ center: ['50%', '54%']
+ },
+ tooltip: {
+ trigger: 'axis',
+ axisPointer: {
+ type: 'cross'
+ }
+ },
+ angleAxis: {
+ type: 'value',
+ startAngle: 0,
+ },
+ radiusAxis: {
+ min: 0
+ },
+ series: [{
+ coordinateSystem: 'polar',
+ name: 'line',
+ type: 'line',
+ showSymbol: false,
+ data: data
+ }],
+ animationDuration: 2000
+};
+</ExampleBaseOption>
+
+<ExampleBaseOption name="two-category-axis" title="双类目轴">
+
+const hours = ['12a', '1a', '2a', '3a', '4a', '5a', '6a',
+ '7a', '8a', '9a','10a','11a',
+ '12p', '1p', '2p', '3p', '4p', '5p',
+ '6p', '7p', '8p', '9p', '10p', '11p'];
+const days = ['Saturday', 'Friday', 'Thursday',
+ 'Wednesday', 'Tuesday', 'Monday', 'Sunday'];
+
+const option = {
+ title: {
+ text: 'Punch Card of Github'
+ },
+ legend: {
+ data: ['Punch Card'],
+ left: 'right'
+ },
+ polar: {},
+ angleAxis: {
+ type: 'category',
+ data: hours,
+ boundaryGap: false
+ },
+ radiusAxis: {
+ type: 'category',
+ data: days
+ }
+};
+</ExampleBaseOption>
+
{{use: partial-component-id(prefix="#")}}
## polarIndex(number) = 0
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org