MCPcopy
hub / github.com/teadocs/numpy-cn / parse

Method parse

scripts/htmlToMd.js:37–183  ·  view source on GitHub ↗
(el)

Source from the content-addressed store, hash-verified

35 }
36
37 parse(el) {
38 let nodeName = el.nodeName;
39 let content = '';
40 switch (nodeName) {
41 case 'SPAN':
42 content = '';
43 break;
44 case 'H1':
45 content = `# ${this.getHtext(el)}\n`;
46 break;
47 case 'H2':
48 content = `\n## ${this.getHtext(el)}\n`;
49 break;
50 case 'H3':
51 content = `\n### ${this.getHtext(el)}\n`;
52 break;
53 case 'H4':
54 content = `\n#### ${this.getHtext(el)}\n`;
55 break;
56 case 'H5':
57 content = `\n##### ${this.getHtext(el)}\n`;
58 break;
59 case 'TABLE': {
60 let tempContent = this.$(el).prop("innerText");
61 tempContent = tempContent.replace(new RegExp(/( )/g), ' | ');
62 let tempArr = tempContent.split('\n');
63 let tempArr2 = tempArr[0].split('|');
64 let tempArr3 = [];
65 Array.from({
66 length: tempArr2.length
67 }).forEach(() => tempArr3.push('---'));
68 tempArr.splice(1, 0, tempArr3.join('|'));
69 tempContent = `\n${tempArr.join('\n')}\n`;
70 content = this.replaceAForTable(tempContent, this.$(el));
71 }
72 break;
73 case 'P': {
74 let className = this.$(el).attr('class');
75 if (className !== 'first admonition-title') {
76 content = this.getPcontent(this.$(el));
77 }
78 }
79 break;
80 case 'IMG': {
81 let imgSrc = this.$(el).attr('src');
82 let imgNameArr = imgSrc.split('/');
83 let imgName = imgNameArr[imgNameArr.length - 1];
84 let fileName = imgName.split('.')[0];
85 content = `\n![${fileName}](${this.baseImgDir}${imgName})\n`;
86 }
87 break;
88 case 'DIV': {
89 let className = this.$(el).attr('class');
90 if (!className) {
91 content = this.getMarkdown(el);
92 } else if (className === 'math notranslate nohighlight') {
93 content = `\n<div class="math notranslate nohighlight">\nIt's a mathematical formula.\n</div>\n`;
94 } else if (className === 'admonition note') {

Callers 9

getMarkdownMethod · 0.80
kFunction · 0.80
Valine.Pure.min.jsFile · 0.80
uFunction · 0.80
hFunction · 0.80
wFunction · 0.80
Valine.min.jsFile · 0.80
dFunction · 0.80
hFunction · 0.80

Calls 5

getHtextMethod · 0.95
replaceAForTableMethod · 0.95
getPcontentMethod · 0.95
getMarkdownMethod · 0.95
uReplaceStrMethod · 0.95

Tested by

no test coverage detected