Skip to content

Commit

Permalink
Switch to own solution
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 committed May 17, 2020
1 parent c0432db commit 3ec542d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 32 deletions.
6 changes: 1 addition & 5 deletions packages/docusaurus-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@
},
"license": "MIT",
"dependencies": {
"@types/remove-markdown": "^0.1.1",
"escape-string-regexp": "^2.0.0",
"fs-extra": "^8.1.0",
"gray-matter": "^4.0.2",
"lodash.camelcase": "^4.3.0",
"lodash.kebabcase": "^4.1.1",
"remark": "^12.0.0",
"remove-markdown": "^0.3.0",
"strip-markdown": "^3.1.2"
"lodash.kebabcase": "^4.1.1"
},
"engines": {
"node": ">=10.9.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-utils/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ describe('load utils', () => {
import Component from '@site/src/components/Component';
import Component from '@site/src/components/Component'
Lorem **ipsum** dolor sit \`amet\`, consectetur _adipiscing_ elit. [**Vestibulum**](#) ex urna, molestie et sagittis ut, varius ac justo :wink:.
Lorem **ipsum** dolor sit \`amet\`, consectetur _adipiscing_ elit. [**Vestibulum**](https://wiktionary.org/wiki/vestibulum) ex urna, ~molestie~ et sagittis ut, varius ac justo :wink:.
Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
`,
Expand All @@ -337,7 +337,7 @@ describe('load utils', () => {
// Content beginning with heading
{
input: `
# Lorem ipsum dolor sit amet
## Lorem ipsum dolor sit amet
Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
`,
Expand Down
27 changes: 18 additions & 9 deletions packages/docusaurus-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import camelCase from 'lodash.camelcase';
import kebabCase from 'lodash.kebabcase';
import escapeStringRegexp from 'escape-string-regexp';
import fs from 'fs-extra';
// import removeMd from 'remove-markdown';
import remark from 'remark';
import strip from 'strip-markdown';

const fileHash = new Map();
export async function generate(
Expand Down Expand Up @@ -188,10 +185,6 @@ export function getSubFolder(file: string, refDir: string): string | null {
// Regex for an import statement.
const importRegexString = '^(.*import){1}(.+){0,1}\\s[\'"](.+)[\'"];?';

function removeMd(markdownString: string): string {
return remark().use(strip).processSync(markdownString.trim()).toString();
}

export function createExcerpt(fileString: string): string | undefined {
let fileContent = fileString.trimLeft();

Expand All @@ -204,8 +197,24 @@ export function createExcerpt(fileString: string): string | undefined {
const fileLines = fileContent.split('\n');

for (let fileLine of fileLines) {
const cleanedLine = removeMd(fileLine)
// Remove definition of admonition.
const cleanedLine = fileLine
// Remove HTML tags.
.replace(/<[^>]*>/g, '')
// Remove ATX-style headers.
.replace(/^\#{1,6}\s*([^#]*)\s*(\#{1,6})?/gm, '$1')
// Remove emphasis and strikethroughs.
.replace(/([\*_~]{1,3})(\S.*?\S{0,1})\1/g, '$2')
// Remove inline links.
.replace(/\[(.*?)\][\[\(].*?[\]\)]/g, '$1')
// Remove inline code.
.replace(/`(.+?)`/g, '$1')
// Remove images.
.replace(/\!\[(.*?)\][\[\(].*?[\]\)]/g, '')
// Remove blockquotes.
.replace(/^\s{0,3}>\s?/g, '')
// Remove footnotes.
.replace(/\[\^.+?\](\: .*?$)?/g, '')
// Remove admonition definition.
.replace(/(:{3}.*)/, '')
// Remove Emoji names within colons include preceding whitespace.
.replace(/\s?(:(::|[^:\n])+:)/g, '')
Expand Down
1 change: 0 additions & 1 deletion packages/docusaurus-utils/types.d.ts

This file was deleted.

15 changes: 0 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2725,11 +2725,6 @@
resolved "https://registry.yarnpkg.com/@types/relateurl/-/relateurl-0.2.28.tgz#6bda7db8653fa62643f5ee69e9f69c11a392e3a6"
integrity sha1-a9p9uGU/piZD9e5p6facEaOS46Y=

"@types/remove-markdown@^0.1.1":
version "0.1.1"
resolved "https://registry.yarnpkg.com/@types/remove-markdown/-/remove-markdown-0.1.1.tgz#c79d3000df412526186b2af3808b85bee68bc907"
integrity sha512-SCYOFMHUqyiJU5M0V2gBB6UDdBhPwma34j0vYX0JgWaqp/74ila2Ops1jt5tB/C1UQXVXqK+is61884bITn3LQ==

"@types/semver@^7.1.0":
version "7.1.0"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.1.0.tgz#c8c630d4c18cd326beff77404887596f96408408"
Expand Down Expand Up @@ -14564,11 +14559,6 @@ remarkable@^2.0.0:
argparse "^1.0.10"
autolinker "^3.11.0"

remove-markdown@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/remove-markdown/-/remove-markdown-0.3.0.tgz#5e4b667493a93579728f3d52ecc1db9ca505dc98"
integrity sha1-XktmdJOpNXlyjz1S7MHbnKUF3Jg=

remove-trailing-separator@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz#c24bce2a283adad5bc3f58e0d48249b92379d8ef"
Expand Down Expand Up @@ -15907,11 +15897,6 @@ strip-json-comments@~2.0.1:
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo=

strip-markdown@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/strip-markdown/-/strip-markdown-3.1.2.tgz#172f6f89f9a98896e65a65422e0507f2bbac1667"
integrity sha512-NjwW6CEefesmHQPs7lof/lgnSriqUnRNOWpnrNPq9A7/yOCdnhaB7DcxlhYuN7WiiRUe349aitAsTQ/ajM9Dmw==

strip-outer@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/strip-outer/-/strip-outer-1.0.1.tgz#b2fd2abf6604b9d1e6013057195df836b8a9d631"
Expand Down

0 comments on commit 3ec542d

Please sign in to comment.