markdown-magic 2.6.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -10
- package/cli.js +5 -82
- package/lib/block-parser-js.test.js +179 -0
- package/lib/block-parser.js +389 -0
- package/lib/{utils/new-parser.test.js → block-parser.test.js} +168 -50
- package/lib/cli.js +234 -0
- package/lib/cli.test.js +409 -0
- package/lib/defaults.js +12 -0
- package/lib/index.js +319 -184
- package/lib/index.test.js +11 -0
- package/lib/options-parser.js +498 -0
- package/lib/options-parser.test.js +1237 -0
- package/lib/process-contents.js +330 -0
- package/lib/process-file.js +34 -0
- package/lib/transforms/code.js +67 -22
- package/lib/transforms/file.js +13 -10
- package/lib/transforms/remote.js +9 -6
- package/lib/transforms/toc.js +136 -64
- package/lib/transforms/wordCount.js +5 -0
- package/lib/utils/fs.js +340 -0
- package/lib/utils/fs.test.js +268 -0
- package/lib/utils/html-to-json/compat.js +42 -0
- package/lib/utils/html-to-json/format.js +64 -0
- package/lib/utils/html-to-json/index.js +37 -0
- package/lib/utils/html-to-json/lexer.js +345 -0
- package/lib/utils/html-to-json/parser.js +146 -0
- package/lib/utils/html-to-json/stringify.js +37 -0
- package/lib/utils/html-to-json/tags.js +171 -0
- package/lib/utils/index.js +19 -0
- package/{cli-utils.js → lib/utils/load-config.js} +2 -6
- package/lib/utils/logs.js +89 -0
- package/lib/utils/md/filters.js +20 -0
- package/lib/utils/md/find-code-blocks.js +80 -0
- package/lib/utils/md/find-date.js +32 -0
- package/lib/utils/md/find-frontmatter.js +94 -0
- package/lib/utils/md/find-frontmatter.test.js +17 -0
- package/lib/utils/md/find-html-tags.js +105 -0
- package/lib/utils/md/find-images.js +102 -0
- package/lib/utils/md/find-links.js +202 -0
- package/lib/utils/md/find-unmatched-html-tags.js +33 -0
- package/lib/utils/md/fixtures/2022-01-22-date-in-filename.md +14 -0
- package/lib/utils/md/fixtures/file-with-frontmatter.md +32 -0
- package/lib/utils/md/fixtures/file-with-links.md +143 -0
- package/lib/utils/md/md.test.js +37 -0
- package/lib/utils/md/parse.js +122 -0
- package/lib/utils/md/utils.js +19 -0
- package/lib/utils/regex-timeout.js +83 -0
- package/lib/utils/regex.js +38 -5
- package/lib/utils/remoteRequest.js +54 -0
- package/lib/utils/syntax.js +79 -0
- package/lib/utils/text.js +260 -0
- package/lib/utils/text.test.js +311 -0
- package/package.json +26 -26
- package/index.js +0 -46
- package/lib/processFile.js +0 -154
- package/lib/transforms/index.js +0 -114
- package/lib/updateContents.js +0 -125
- package/lib/utils/_md.test.js +0 -63
- package/lib/utils/new-parser.js +0 -412
- package/lib/utils/weird-parse.js +0 -230
- package/lib/utils/weird-parse.test.js +0 -217
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
const { onlyUnique, isImage, isRelative } = require('./filters')
|
|
2
|
+
|
|
3
|
+
// https://regex101.com/r/In5HtG/3
|
|
4
|
+
const LIVE_LINKS_REGEX = /(?:['"(])((?:https?:\/\/)[\w\d\-_,./?=#%:+&]{3,})/gmi
|
|
5
|
+
// https://regex101.com/r/Nywerx/3
|
|
6
|
+
const RELATIVE_LINKS_REGEX = /(src|href|\()=?(['"/])(?!(?:(?:https?|ftp):\/\/|data:))(\.?\/)?([\w\d-_./,?=#%:+&]+)(?:['")])?/gim
|
|
7
|
+
// https://regex101.com/r/u2DwY2/2/
|
|
8
|
+
const MARKDOWN_IMAGE_REGEX = /!\[[^\]]*\]\((.*?)\s*("(?:.*[^"])")?\s*\)/g
|
|
9
|
+
|
|
10
|
+
const LINK_PATTERN = /^https?:\/\//
|
|
11
|
+
|
|
12
|
+
function isLocal(link) {
|
|
13
|
+
return isRelative(link)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function isRemote(link) {
|
|
17
|
+
return !isRelative(link)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Finds all links in text relative or otherwise
|
|
22
|
+
* @param {string} mdContents
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
function findLinks(text, opts = {}) {
|
|
26
|
+
const { unique = true } = opts
|
|
27
|
+
const live = findLiveLinks(text)
|
|
28
|
+
const relative = findRelativeLinks(text)
|
|
29
|
+
const normalLinks = live.concat(relative)
|
|
30
|
+
const mdImgLinks = findMarkdownImageLinks(text)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
let frontmatterLinks = []
|
|
34
|
+
if (opts.frontmatter) {
|
|
35
|
+
frontmatterLinks = findLinksInFrontMatter(opts.frontmatter, findLinks)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const allLinks = normalLinks.concat(mdImgLinks).concat(frontmatterLinks)
|
|
39
|
+
const all = (!unique) ? allLinks : allLinks.filter(onlyUnique)
|
|
40
|
+
|
|
41
|
+
let images = mdImgLinks
|
|
42
|
+
let links = []
|
|
43
|
+
for (let i = 0; i < all.length; i++) {
|
|
44
|
+
const link = all[i]
|
|
45
|
+
if (isImage(link)) {
|
|
46
|
+
images.push(link)
|
|
47
|
+
} else {
|
|
48
|
+
links.push(link)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// const allImages = normalLinks.filter((link) => isImage(link)).concat(mdLinks)
|
|
52
|
+
// const links = normalLinks.filter((link) => !isImage(link))
|
|
53
|
+
const allImg = images.filter(onlyUnique)
|
|
54
|
+
const allLink = links.filter(onlyUnique).filter(function(el) {
|
|
55
|
+
return allImg.indexOf(el) < 0
|
|
56
|
+
})
|
|
57
|
+
return {
|
|
58
|
+
// all,
|
|
59
|
+
// live,
|
|
60
|
+
// relative,
|
|
61
|
+
// frontmatter: frontmatterLinks,
|
|
62
|
+
links: {
|
|
63
|
+
all: allLink,
|
|
64
|
+
relative: allLink.filter(isLocal),
|
|
65
|
+
live: allLink.filter(isRemote)
|
|
66
|
+
},
|
|
67
|
+
images: {
|
|
68
|
+
all: allImg,
|
|
69
|
+
relative: allImg.filter(isLocal),
|
|
70
|
+
live: allImg.filter(isRemote)
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function findMarkdownImageLinks(text) {
|
|
76
|
+
let matches
|
|
77
|
+
let imageLinks = []
|
|
78
|
+
while ((matches = MARKDOWN_IMAGE_REGEX.exec(text)) !== null) {
|
|
79
|
+
if (matches.index === MARKDOWN_IMAGE_REGEX.lastIndex) {
|
|
80
|
+
MARKDOWN_IMAGE_REGEX.lastIndex++ // avoid infinite loops with zero-width matches
|
|
81
|
+
}
|
|
82
|
+
const [ match, image, altText ] = matches
|
|
83
|
+
imageLinks.push(image)
|
|
84
|
+
}
|
|
85
|
+
return imageLinks.filter(onlyUnique)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Finds all links in markdown <a>, <img> and md link format []()
|
|
90
|
+
* @param {string} text
|
|
91
|
+
* @returns
|
|
92
|
+
*/
|
|
93
|
+
function findLiveLinks(text) {
|
|
94
|
+
let matches
|
|
95
|
+
let links = []
|
|
96
|
+
while ((matches = LIVE_LINKS_REGEX.exec(text)) !== null) {
|
|
97
|
+
if (matches.index === LIVE_LINKS_REGEX.lastIndex) {
|
|
98
|
+
LIVE_LINKS_REGEX.lastIndex++ // avoid infinite loops with zero-width matches
|
|
99
|
+
}
|
|
100
|
+
const [ match, url ] = matches
|
|
101
|
+
links.push(url)
|
|
102
|
+
}
|
|
103
|
+
return links.filter(onlyUnique)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/*
|
|
107
|
+
Match relative links
|
|
108
|
+
<h1 jdjdjjdjd=lksjskljfsdlk="jdjdj">Netlify + FaunaDB
|
|
109
|
+
<a href="https://app.netlify.com/start/deploy?repository=https://github.com/netlify/netlify-faunadb-example&stack=fauna">
|
|
110
|
+
<img src="../../../../img/deploy/lol.svg">
|
|
111
|
+
</a>
|
|
112
|
+
</h1>
|
|
113
|
+
[link](/my-great-page)
|
|
114
|
+
<a href="img/deploy/one.svg">cool</a>
|
|
115
|
+
<img src="img/deploy/duplicate.svg" />
|
|
116
|
+
<img src="img/deploy/duplicate.svg" >
|
|
117
|
+
<img src="/img/deploy/three.svg" />
|
|
118
|
+
<img src='/img/deploy/four.svg' />
|
|
119
|
+
<img src='./img/deploy/five.svg' />
|
|
120
|
+
<img src='../img/deploy/button.svg' />
|
|
121
|
+
<img src='../../img/deploy/button.svg' />
|
|
122
|
+
<img src="https://www.netlify.com/img/deploy/button.svg" />
|
|
123
|
+
<img src="https://www.netlify.com/img/deploy/button.svg" />
|
|
124
|
+

|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
function findRelativeLinks(text) {
|
|
128
|
+
let matches
|
|
129
|
+
let relLinks = []
|
|
130
|
+
while ((matches = RELATIVE_LINKS_REGEX.exec(text)) !== null) {
|
|
131
|
+
if (matches.index === RELATIVE_LINKS_REGEX.lastIndex) {
|
|
132
|
+
RELATIVE_LINKS_REGEX.lastIndex++ // avoid infinite loops with zero-width matches
|
|
133
|
+
}
|
|
134
|
+
// console.log(matches)
|
|
135
|
+
const [ match, _, start, link, x ] = matches
|
|
136
|
+
const one = (start === '/') ? start : ''
|
|
137
|
+
const two = (link === '/') ? link : ''
|
|
138
|
+
relLinks.push(`${one}${two}${x}`)
|
|
139
|
+
}
|
|
140
|
+
return relLinks.filter(onlyUnique)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function findLinksInFrontMatter(data, linkFinder) {
|
|
144
|
+
const yamlStrings = traverse(data)
|
|
145
|
+
const linksInYml = yamlStrings.map((string) => {
|
|
146
|
+
if (LINK_PATTERN.test(string)) {
|
|
147
|
+
return [string]
|
|
148
|
+
}
|
|
149
|
+
// console.log('string', string)
|
|
150
|
+
return linkFinder(string)
|
|
151
|
+
})
|
|
152
|
+
.filter((x) => {
|
|
153
|
+
if (Array.isArray(x)) {
|
|
154
|
+
return x.length
|
|
155
|
+
}
|
|
156
|
+
if (x && x.all) {
|
|
157
|
+
return x.all.length
|
|
158
|
+
}
|
|
159
|
+
return true
|
|
160
|
+
})
|
|
161
|
+
.map((x) => {
|
|
162
|
+
if (typeof x === 'string') {
|
|
163
|
+
return x
|
|
164
|
+
}
|
|
165
|
+
if (typeof x === 'object' && x.all) {
|
|
166
|
+
return x.all
|
|
167
|
+
}
|
|
168
|
+
return x
|
|
169
|
+
})
|
|
170
|
+
.flat()
|
|
171
|
+
// console.log('linksInYml', linksInYml)
|
|
172
|
+
return linksInYml
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function traverse(x, arr = []) {
|
|
176
|
+
if (typeof x === 'string') {
|
|
177
|
+
arr.push(x)
|
|
178
|
+
} else if (isArray(x)) {
|
|
179
|
+
traverseArray(x, arr)
|
|
180
|
+
} else if ((typeof x === 'object') && (x !== null)) {
|
|
181
|
+
traverseObject(x, arr)
|
|
182
|
+
}
|
|
183
|
+
return arr
|
|
184
|
+
}
|
|
185
|
+
function traverseArray(arr, acc) {
|
|
186
|
+
arr.forEach((x) => traverse(x, acc))
|
|
187
|
+
}
|
|
188
|
+
function traverseObject(obj, acc) {
|
|
189
|
+
for (var key in obj) {
|
|
190
|
+
if (obj.hasOwnProperty(key)) traverse(obj[key], acc)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function isArray(o) {
|
|
195
|
+
return Object.prototype.toString.call(o) === '[object Array]'
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
module.exports = {
|
|
199
|
+
findLinks,
|
|
200
|
+
findLiveLinks,
|
|
201
|
+
findRelativeLinks
|
|
202
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const { getLineNumberFromMatch } = require('./utils')
|
|
2
|
+
// const { voidTags } = require('../html-to-json/tags')
|
|
3
|
+
|
|
4
|
+
// https://regex101.com/r/he9l06/2
|
|
5
|
+
// http://xahlee.info/js/html5_non-closing_tag.html
|
|
6
|
+
// voidTags
|
|
7
|
+
const CLOSE_TAG_REGEX = /<(br|hr|img|embed|col|link|meta)(([^>]*)([^/])(>)|>)/g
|
|
8
|
+
|
|
9
|
+
function findUnmatchedHtmlTags(block, filePath) {
|
|
10
|
+
let matches
|
|
11
|
+
let errors = []
|
|
12
|
+
const msg = (filePath) ? ` in ${filePath}` : ''
|
|
13
|
+
while ((matches = CLOSE_TAG_REGEX.exec(block)) !== null) {
|
|
14
|
+
if (matches.index === CLOSE_TAG_REGEX.lastIndex) {
|
|
15
|
+
CLOSE_TAG_REGEX.lastIndex++ // avoid infinite loops with zero-width matches
|
|
16
|
+
}
|
|
17
|
+
// console.log(matches)
|
|
18
|
+
const [ _, tag, insideOrEnd ] = matches
|
|
19
|
+
const lineNumber = getLineNumberFromMatch(block, matches)
|
|
20
|
+
const fixed = (insideOrEnd === '>') ? '/>' : `${insideOrEnd.substring(0, insideOrEnd.length - 1)}/>`
|
|
21
|
+
errors.push({
|
|
22
|
+
message: `Unclosing HTML tag on line ${lineNumber}${msg}.\n Need closing tag "/>" on: \n${_}`,
|
|
23
|
+
brokenTag: _,
|
|
24
|
+
correctUsage: `<${tag}${fixed}`
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
return errors
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = {
|
|
31
|
+
findUnmatchedHtmlTags,
|
|
32
|
+
CLOSE_TAG_REGEX
|
|
33
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Welcome to ABC
|
|
3
|
+
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
|
|
4
|
+
thumbnail: https://dope-frontmatter.com/img/deploy/button.svg
|
|
5
|
+
categories:
|
|
6
|
+
- company
|
|
7
|
+
authors:
|
|
8
|
+
- Bob Bob
|
|
9
|
+
- Joe Smoe
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
**Welcome to ABC!** Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur [keynote presentation](https://youtu.be/A1bL4pHuivU).
|
|
13
|
+
|
|
14
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
draft: true
|
|
3
|
+
template: page
|
|
4
|
+
path: /foo/bar
|
|
5
|
+
title: Default title
|
|
6
|
+
components:
|
|
7
|
+
- type: PageHeading
|
|
8
|
+
heading: Nice
|
|
9
|
+
subHeading: Add it
|
|
10
|
+
- type: content
|
|
11
|
+
content: >-
|
|
12
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur
|
|
16
|
+
- type: content
|
|
17
|
+
content: |-
|
|
18
|
+
More content
|
|
19
|
+
|
|
20
|
+
<ComponentXyz />
|
|
21
|
+
|
|
22
|
+
stuff
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
- type: content
|
|
26
|
+
content: Even more content
|
|
27
|
+
seo:
|
|
28
|
+
title: xyz
|
|
29
|
+
description: seo description here
|
|
30
|
+
updatedBy: David Wells
|
|
31
|
+
updatedAt: 2022-11-10T01:52:37.383Z
|
|
32
|
+
---
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Welcome to ABC
|
|
3
|
+
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
|
|
4
|
+
date: '2020-06-30'
|
|
5
|
+
thumbnail: https://dope-frontmatter.com/img/deploy/button.svg
|
|
6
|
+
components:
|
|
7
|
+
- type: PageHeading
|
|
8
|
+
heading: Nice
|
|
9
|
+
subHeading: Add it
|
|
10
|
+
- type: content
|
|
11
|
+
content: >-
|
|
12
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur
|
|
13
|
+
|
|
14
|
+
<a href="https://funky-frontmatter.com">funky</a>
|
|
15
|
+
|
|
16
|
+
<img src='/img/in-nested-frontmatter/button.svg' />
|
|
17
|
+
|
|
18
|
+

|
|
19
|
+
|
|
20
|
+
<img src='https://frontmatter.com/img/deploy/button.svg' />
|
|
21
|
+
|
|
22
|
+
we've created a [detailed blog post](https://www.front.com/blog/open-beta-changes) to help those with the migration process. We're confident these changes, once released, will make for a significantly better experience for current and future users.
|
|
23
|
+
categories:
|
|
24
|
+
- company
|
|
25
|
+
authors:
|
|
26
|
+
- Bob Bob
|
|
27
|
+
- Joe Smoe
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
**Welcome to ABC!** Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur [keynote presentation](https://youtu.be/A1bL4pHuivU).
|
|
31
|
+
|
|
32
|
+
<img src='/img/deploy/button.svg' />
|
|
33
|
+
|
|
34
|
+
<img src='./img/deploy/button.svg' />
|
|
35
|
+
|
|
36
|
+
<img src='../img/deploy/button.svg' />
|
|
37
|
+
|
|
38
|
+
<img src="https://www.netlify.com/img/deploy/button.svg" />
|
|
39
|
+
|
|
40
|
+
<img src="https://www.netlify.com/img/deploy/button.svg" />
|
|
41
|
+
|
|
42
|
+
<img src='https://fooo.com/img/deploy/button.svg' />
|
|
43
|
+
|
|
44
|
+

|
|
45
|
+
|
|
46
|
+

|
|
47
|
+
|
|
48
|
+

|
|
49
|
+
|
|
50
|
+

|
|
51
|
+
|
|
52
|
+
Hear Bob Bobster discuss the evolution of Serverless and the launch of ABC at the AWS Serverless Community Day.
|
|
53
|
+
|
|
54
|
+
<iframe width="560" height="315" src="https://www.youtube.com/embed/KX7tj3giizI" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe>
|
|
55
|
+
|
|
56
|
+
<a href="https://app.netlify.com/start/deploy">
|
|
57
|
+
<img src="/img/deploy/button.svg">
|
|
58
|
+
</a>
|
|
59
|
+
|
|
60
|
+
<a href="/foobar">
|
|
61
|
+
<img src="/img/deploy/button.svg">
|
|
62
|
+
</a>
|
|
63
|
+
|
|
64
|
+
Title xyz
|
|
65
|
+
============================
|
|
66
|
+
|
|
67
|
+
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem
|
|
68
|
+
|
|
69
|
+
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem
|
|
70
|
+
|
|
71
|
+
Legacy Alternatives
|
|
72
|
+
===================
|
|
73
|
+
|
|
74
|
+
It vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id
|
|
75
|
+
|
|
76
|
+
Escaping the "Single Box" Blockchain Limitation
|
|
77
|
+
===============================================
|
|
78
|
+
|
|
79
|
+
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
|
|
80
|
+
|
|
81
|
+
<Author foo='bar' foo='bing'>
|
|
82
|
+
<Child />
|
|
83
|
+
</Author>
|
|
84
|
+
|
|
85
|
+
```graphql
|
|
86
|
+
mutation _files__add($input: ABC_File_Input_!, $syncMode: ABC_SyncMode = NODE_COMMITTED)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
To override the default, include the `syncMode` option as such:
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
/* Hello there */
|
|
93
|
+
const response = await entities.product.add(
|
|
94
|
+
{
|
|
95
|
+
name: 'super-widget',
|
|
96
|
+
inventory: 100,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
syncMode: 'ASYNC', <-- example syncMode instruction
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
console.log(response?.transaction?.transactionId);
|
|
104
|
+
console.log(response?.transaction?._id);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Title xyz
|
|
108
|
+
===========================
|
|
109
|
+
|
|
110
|
+
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat
|
|
111
|
+
|
|
112
|
+
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat
|
|
113
|
+
|
|
114
|
+
<!-- doc-gen {{functionName}} foo={{ rad: 'yellow' }} -->
|
|
115
|
+
xyz
|
|
116
|
+
<!-- end-doc-gen -->
|
|
117
|
+
|
|
118
|
+
Hello title
|
|
119
|
+
=======================
|
|
120
|
+
|
|
121
|
+
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat remaining confident that their solutions will work on _any_ public cloud, not just a single vendor. Interested in experiencing it for yourself? [Sign up](https://ABC.com/sign-up) to join our preview access program, starting in late July.
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
<!-- doc-gen {{functionName}}
|
|
125
|
+
foo={{ rad: 'yellow' }}
|
|
126
|
+
baz=bar
|
|
127
|
+
fun=['array']
|
|
128
|
+
-->
|
|
129
|
+
xyz
|
|
130
|
+
<!-- end-doc-gen -->
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
We’re excited to be on this journey to help customers solve some of their greatest challenges by making code and data easier to share, protect, and secure. **Welcome to ABC and welcome to a new era of sharing made easy!**
|
|
134
|
+
|
|
135
|
+
<Author
|
|
136
|
+
arr={['one', 'two']}
|
|
137
|
+
foo={{ "bar": true }}
|
|
138
|
+
baz='string'
|
|
139
|
+
/>
|
|
140
|
+
|
|
141
|
+
_Bob & Joe_
|
|
142
|
+
|
|
143
|
+
_Looking for your next great opportunity?_ [_We’re hiring!_](http://jobs.ABC.net)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const { test } = require('uvu')
|
|
4
|
+
const assert = require('uvu/assert')
|
|
5
|
+
const { deepLog } = require('../logs')
|
|
6
|
+
const { stringify } = require('../html-to-json')
|
|
7
|
+
const { parseMarkdown } = require('./parse')
|
|
8
|
+
const { findLinks } = require('./find-links')
|
|
9
|
+
const { findFrontmatter } = require('./find-frontmatter')
|
|
10
|
+
|
|
11
|
+
const FILE_PATH = path.join(__dirname, 'fixtures/file-with-links.md')
|
|
12
|
+
// const FILE_PATH = path.join(__dirname, 'fixtures/2022-01-22-date-in-filename.md')
|
|
13
|
+
const fileContents = fs.readFileSync(FILE_PATH, 'utf-8')
|
|
14
|
+
|
|
15
|
+
test('parseMarkdown API', async () => {
|
|
16
|
+
const res = parseMarkdown(fileContents, { filePath: FILE_PATH })
|
|
17
|
+
// deepLog(res)
|
|
18
|
+
assert.is(typeof res, 'object')
|
|
19
|
+
assert.is(typeof res.ast, 'object')
|
|
20
|
+
assert.is(typeof res.data, 'object')
|
|
21
|
+
assert.is(typeof res.content, 'string')
|
|
22
|
+
assert.is(typeof res.codeBlocks, 'object')
|
|
23
|
+
assert.is(Array.isArray(res.errors), true)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
// test('File have correct extensions', async () => {
|
|
27
|
+
// const { data } = findFrontmatter(fileWithLinks, FILE_PATH)
|
|
28
|
+
// console.log('frontmatter data', data)
|
|
29
|
+
// const links = findLinks(fileWithLinks, { frontmatter: data })
|
|
30
|
+
// // console.log('links', links)
|
|
31
|
+
// // console.log('FILE_PATH', FILE_PATH)
|
|
32
|
+
// // console.log('parseMarkdown')
|
|
33
|
+
// // const x = parseMarkdown(fileWithLinks, { filePath: FILE_PATH })
|
|
34
|
+
// // deepLog(x)
|
|
35
|
+
// })
|
|
36
|
+
|
|
37
|
+
test.run()
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// const { validateHtml } = require('./validate-html')
|
|
2
|
+
const { findFrontmatter } = require('./find-frontmatter')
|
|
3
|
+
const { parse } = require('../html-to-json')
|
|
4
|
+
const { getLineCount } = require('./utils')
|
|
5
|
+
const { findUnmatchedHtmlTags } = require('./find-unmatched-html-tags')
|
|
6
|
+
const { findLinks } = require('./find-links')
|
|
7
|
+
const { findDate } = require('./find-date')
|
|
8
|
+
const { findCodeBlocks, REMOVE_CODE_BLOCK_REGEX } = require('./find-code-blocks')
|
|
9
|
+
// const { findImages, findLiveImages } = require('./find-images')
|
|
10
|
+
// const { findHtmlTags } = require('./find-html-tags')
|
|
11
|
+
|
|
12
|
+
function parseMarkdown(text, opts = {}) {
|
|
13
|
+
const { filePath, validateHtml } = opts
|
|
14
|
+
let errors = []
|
|
15
|
+
let frontmatter = {}
|
|
16
|
+
let alreadySetError = false
|
|
17
|
+
try {
|
|
18
|
+
frontmatter = findFrontmatter(text, filePath)
|
|
19
|
+
} catch (err) {
|
|
20
|
+
console.log(`Broken frontmatter in ${filePath}...`)
|
|
21
|
+
errors.push(err.message)
|
|
22
|
+
alreadySetError = true
|
|
23
|
+
}
|
|
24
|
+
const { data, content = '', rawFrontMatter = '' } = frontmatter
|
|
25
|
+
if (!data || !Object.keys(data).length) {
|
|
26
|
+
if (!alreadySetError) {
|
|
27
|
+
errors.push(`Missing or broken frontmatter in ${filePath}. Double check file for --- frontmatter tags`)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// const imagesInYml = findLinksInFrontMatter(data, findLiveImages)
|
|
32
|
+
// console.log('linksInYml', linksInYml)
|
|
33
|
+
// const links = findLiveLinks(text)
|
|
34
|
+
//console.log(`links ${filePath}`, links)
|
|
35
|
+
// const relativeLinks = findRelativeLinks(text)
|
|
36
|
+
// console.log(`relativeLinks ${filePath}`, relativeLinks)
|
|
37
|
+
/* gets all images in file */
|
|
38
|
+
// const images = findLiveImages(text) // findImages(text)
|
|
39
|
+
// console.log(`images ${filePath}`, images)
|
|
40
|
+
// const htmlTags = findHtmlTags(text)
|
|
41
|
+
const linkData = findLinks(text)
|
|
42
|
+
|
|
43
|
+
const html = parse(content, {
|
|
44
|
+
includePositions: true,
|
|
45
|
+
offset: {
|
|
46
|
+
lineOffset: getLineCount(rawFrontMatter),
|
|
47
|
+
charOffset: rawFrontMatter.length
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
// console.log(`htmlTags ${filePath}`, htmlTags)
|
|
51
|
+
const codeBlocks = findCodeBlocks(text, filePath)
|
|
52
|
+
// console.log(`codeBlocks ${filePath}`, codeBlocks)
|
|
53
|
+
const tagsErrors = findUnmatchedHtmlTags(text, filePath)
|
|
54
|
+
|
|
55
|
+
// const htmlValidationTags = validateHtmlTags(htmlTags, filePath)
|
|
56
|
+
// if (htmlValidationTags && htmlValidationTags.length) {
|
|
57
|
+
// errors = errors.concat(htmlValidationTags)
|
|
58
|
+
// }
|
|
59
|
+
|
|
60
|
+
let htmlValidation = []
|
|
61
|
+
if (validateHtml) {
|
|
62
|
+
const contentsNoCodeBlocks = content.replace(REMOVE_CODE_BLOCK_REGEX, '')
|
|
63
|
+
htmlValidation = validateHtml(contentsNoCodeBlocks, filePath)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (htmlValidation && htmlValidation.length) {
|
|
67
|
+
// console.log('htmlValidation', htmlValidation)
|
|
68
|
+
errors = errors.concat(htmlValidation)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (tagsErrors && tagsErrors.length) {
|
|
72
|
+
errors = errors.concat(tagsErrors)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (codeBlocks.errors && codeBlocks.errors.length) {
|
|
76
|
+
errors = errors.concat(codeBlocks.errors)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const frontMatterData = data || {}
|
|
80
|
+
const date = findDate({
|
|
81
|
+
frontmatter: frontMatterData,
|
|
82
|
+
filePath
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const markdownInfo = {
|
|
86
|
+
...(filePath) ? { filePath } : {},
|
|
87
|
+
...(date) ? { date } : {},
|
|
88
|
+
ast: html,
|
|
89
|
+
data: frontMatterData,
|
|
90
|
+
links: linkData.links,
|
|
91
|
+
images: linkData.images,
|
|
92
|
+
codeBlocks,
|
|
93
|
+
content,
|
|
94
|
+
errors,
|
|
95
|
+
// frontMatterRaw: rawFrontMatter,
|
|
96
|
+
// ...frontmatter
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* // Debugger
|
|
100
|
+
const path = require('path')
|
|
101
|
+
if (path.basename(filePath)=== '2020-06-30-welcome-to-vendia.md') {
|
|
102
|
+
// console.log('text', text)
|
|
103
|
+
// console.log('Frontmatter')
|
|
104
|
+
// console.log(data)
|
|
105
|
+
// console.log('findLinks')
|
|
106
|
+
// deepLog(links)
|
|
107
|
+
// console.log('components')
|
|
108
|
+
// deepLog(components)
|
|
109
|
+
console.log('markdownInfo')
|
|
110
|
+
deepLog(markdownInfo)
|
|
111
|
+
|
|
112
|
+
deepLog(stringify(html))
|
|
113
|
+
process.exit(1)
|
|
114
|
+
}
|
|
115
|
+
/** */
|
|
116
|
+
|
|
117
|
+
return markdownInfo
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
module.exports = {
|
|
121
|
+
parseMarkdown
|
|
122
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
function getLineNumberFromMatch(text = '', matches) {
|
|
4
|
+
return getLineCount(text.substr(0, matches.index))
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function getLines(str = '') {
|
|
8
|
+
return str.split(/\r\n|\r|\n/)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function getLineCount(str = '') {
|
|
12
|
+
return getLines(str).length
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
getLines,
|
|
17
|
+
getLineCount,
|
|
18
|
+
getLineNumberFromMatch
|
|
19
|
+
}
|