Skip to content

Commit 3ef6fe7

Browse files
authored
Merge pull request mrin9#58 from andyrooger/53-better-md-support
Offload markdown parsing to marked and html-to-pdfmake
2 parents 2ae7bdc + d2cc501 commit 3ef6fe7

4 files changed

Lines changed: 19 additions & 134 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"main": "./src/rapipdf.js",
2929
"module": "./src/rapipdf.js",
3030
"dependencies": {
31+
"html-to-pdfmake": "^2.0.2",
3132
"marked": "^0.8.2",
3233
"pdfmake": "^0.1.65",
3334
"swagger-client": "^3.10.0",
@@ -46,7 +47,6 @@
4647
"clean-webpack-plugin": "^3.0.0",
4748
"compression-webpack-plugin": "^3.1.0",
4849
"css-loader": "^3.4.2",
49-
"trim-right": "^1.0.1",
5050
"eslint": "^6.8.0",
5151
"eslint-config-airbnb": "^18.1.0",
5252
"eslint-import-resolver-webpack": "^0.12.1",
@@ -57,6 +57,7 @@
5757
"html-webpack-plugin": "^4.0.2",
5858
"inspectpack": "^4.4.0",
5959
"style-loader": "^1.1.3",
60+
"trim-right": "^1.0.1",
6061
"webpack": "^4.42.1",
6162
"webpack-bundle-analyzer": "^3.6.1",
6263
"webpack-cli": "^3.3.11",

src/markdown.js

Lines changed: 0 additions & 120 deletions
This file was deleted.

src/pdf-parts-gen.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import marked from 'marked';
2+
import htmlToPdfmake from 'html-to-pdfmake';
23
import { rowLinesTableLayout } from '@/table-layouts';
3-
import { getMarkDownDef } from '@/markdown';
44
import {
55
getTypeInfo,
66
schemaInObjectNotation,
77
objectToTree,
88
objectToTableTree,
99
} from '@/object-tree-gen';
1010

11+
function markdownToPdfmake(markdown) {
12+
const html = marked(markdown);
13+
return htmlToPdfmake(html);
14+
}
15+
1116
// Info Def
1217
export function getInfoDef(spec, bookTitle, localize) {
1318
let content;
@@ -46,9 +51,8 @@ export function getInfoDef(spec, bookTitle, localize) {
4651

4752
let specInfDescrMarkDef;
4853
if (spec.info.description) {
49-
const tokens = marked.lexer(spec.info.description);
5054
specInfDescrMarkDef = {
51-
stack: getMarkDownDef(tokens),
55+
stack: markdownToPdfmake(spec.info.description),
5256
style: ['topMargin3'],
5357
};
5458
} else {
@@ -337,20 +341,17 @@ export function getApiDef(spec, filterPath, schemaStyle, localize, includeExampl
337341
});
338342
operationContent.push({ text: '', style: ['topMarginRegular'] });
339343

340-
let pathSummaryMarkDef; let pathDescrMarkDef; let
341-
tokens;
344+
let pathSummaryMarkDef; let pathDescrMarkDef;
342345
if (path.summary) {
343-
tokens = marked.lexer(path.summary);
344346
pathSummaryMarkDef = {
345-
stack: getMarkDownDef(tokens),
347+
stack: markdownToPdfmake(path.summary),
346348
style: ['primary', 'b'],
347349
};
348350
operationContent.push(pathSummaryMarkDef);
349351
}
350352
if (path.description && path.description.trim() !== path.summary.trim()) {
351-
tokens = marked.lexer(path.description);
352353
pathDescrMarkDef = {
353-
stack: getMarkDownDef(tokens),
354+
stack: markdownToPdfmake(path.description),
354355
};
355356
operationContent.push(pathDescrMarkDef);
356357
}
@@ -418,12 +419,10 @@ export function getApiDef(spec, filterPath, schemaStyle, localize, includeExampl
418419

419420
if (pathSeq > 0) {
420421
tagSeq += 1;
421-
let tagDescrMarkDef; let
422-
tokens;
422+
let tagDescrMarkDef;
423423
if (tag.description) {
424-
tokens = marked.lexer(tag.description);
425424
tagDescrMarkDef = {
426-
stack: getMarkDownDef(tokens),
425+
stack: markdownToPdfmake(tag.description),
427426
style: ['topMarginRegular'],
428427
};
429428
} else {

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4368,6 +4368,11 @@ html-minifier-terser@^5.0.1:
43684368
relateurl "^0.2.7"
43694369
terser "^4.6.3"
43704370

4371+
html-to-pdfmake@^2.0.2:
4372+
version "2.0.2"
4373+
resolved "https://registry.yarnpkg.com/html-to-pdfmake/-/html-to-pdfmake-2.0.2.tgz#2ad2062904278e4679081617d216d72a00d06244"
4374+
integrity sha512-fZi5xTSgVY76CnnaWUtnBeoaEcDXFbD+p/cSuf9Z1PcwIXzqUHXNPcFfRDN47rex6jhcsRJM0RaUp0JDIg0Y3g==
4375+
43714376
html-webpack-plugin@^4.0.2:
43724377
version "4.0.4"
43734378
resolved "https://registry.yarnpkg.com/html-webpack-plugin/-/html-webpack-plugin-4.0.4.tgz#90cdfb168094e93e047174d9baca098ec5540636"

0 commit comments

Comments
 (0)