Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
57cadd079c | |||
0ead80750a | |||
3b2f8928de | |||
92a1b589e7 | |||
23f2cc9e6d | |||
813af0c232 | |||
16b21ff6bc | |||
c42f3ee1b7 |
@ -12,6 +12,9 @@ stages:
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
@ -97,10 +100,9 @@ codequality:
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
|
@ -9,7 +9,7 @@
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartmarkdown",
|
||||
"shortDescription": "do more with markdown files",
|
||||
"description": "do more with markdown files",
|
||||
"npmPackagename": "@pushrocks/smartmarkdown",
|
||||
"license": "MIT"
|
||||
}
|
||||
|
24801
package-lock.json
generated
24801
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
27
package.json
27
package.json
@ -1,32 +1,37 @@
|
||||
{
|
||||
"name": "@pushrocks/smartmarkdown",
|
||||
"version": "2.0.11",
|
||||
"version": "3.0.0",
|
||||
"private": false,
|
||||
"description": "do more with markdown files",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "tstest test/",
|
||||
"build": "tsbuild --web"
|
||||
"build": "tsbuild --web --allowimplicitany --skiplibcheck"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.27",
|
||||
"@gitzone/tsrun": "^1.2.17",
|
||||
"@gitzone/tstest": "^1.0.57",
|
||||
"@pushrocks/tapbundle": "^3.2.14",
|
||||
"@types/node": "^16.10.2",
|
||||
"@gitzone/tsbuild": "^2.1.61",
|
||||
"@gitzone/tsrun": "^1.2.32",
|
||||
"@gitzone/tstest": "^1.0.71",
|
||||
"@pushrocks/tapbundle": "^5.0.3",
|
||||
"@types/node": "^17.0.34",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartyaml": "^2.0.5",
|
||||
"@types/turndown": "^5.0.1",
|
||||
"remark": "^13.0.0",
|
||||
"remark-frontmatter": "^3.0.0",
|
||||
"remark-html": "^13.0.0",
|
||||
"remark-frontmatter": "^4.0.1",
|
||||
"remark-gfm": "^3.0.1",
|
||||
"remark-html": "^15.0.1",
|
||||
"remark-parse": "^10.0.1",
|
||||
"remark-stringify": "^10.0.2",
|
||||
"turndown": "^7.1.1",
|
||||
"turndown-plugin-gfm": "^1.0.2"
|
||||
"turndown-plugin-gfm": "^1.0.2",
|
||||
"unified": "^10.1.2"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
@ -1,17 +1,31 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartmarkdown from '../ts/index';
|
||||
import * as smartmarkdown from '../ts/index.js';
|
||||
|
||||
let smartMarkdownInstance: smartmarkdown.SmartMarkdown;
|
||||
|
||||
tap.test('should create a valid instance of SmartMarkdown', async () => {
|
||||
smartMarkdownInstance = new smartmarkdown.SmartMarkdown();
|
||||
expect(smartMarkdownInstance).to.be.instanceOf(smartmarkdown.SmartMarkdown);
|
||||
expect(smartMarkdownInstance).toBeInstanceOf(smartmarkdown.SmartMarkdown);
|
||||
});
|
||||
|
||||
tap.test('should convert a markdown string to html', async () => {
|
||||
const markdownString = '# Hi!';
|
||||
const htmlString = await smartMarkdownInstance.markdownToHtml(markdownString);
|
||||
expect(htmlString).to.equal('<h1>Hi!</h1>\n');
|
||||
const mdParsedResult = await smartMarkdownInstance.getMdParsedResultFromMarkdown(markdownString);
|
||||
const htmlString = mdParsedResult.html;
|
||||
expect(htmlString).toEqual('<h1>Hi!</h1>\n');
|
||||
});
|
||||
|
||||
tap.test('should get frontmatter', async () => {
|
||||
const markdownString = `---
|
||||
hello: yes
|
||||
---
|
||||
|
||||
# hello there
|
||||
`;
|
||||
const mdParsedResult = await smartMarkdownInstance.getMdParsedResultFromMarkdown(markdownString);
|
||||
|
||||
expect(mdParsedResult.frontmatterData.hello).toEqual('yes');
|
||||
|
||||
});
|
||||
|
||||
tap.test('should convert a html string to markdown', async () => {
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartmarkdown',
|
||||
version: '3.0.0',
|
||||
description: 'do more with markdown files'
|
||||
}
|
19
ts/index.ts
19
ts/index.ts
@ -1,20 +1,17 @@
|
||||
import * as plugins from './smartmarkdown.plugins';
|
||||
import * as plugins from './smartmarkdown.plugins.js';
|
||||
import { MdParsedResult } from './smartmarkdown.classes.mdparsedresult.js';
|
||||
|
||||
export class SmartMarkdown {
|
||||
constructor() {}
|
||||
|
||||
/**
|
||||
* converts markdown to html
|
||||
* @param mdString
|
||||
* create a MdParsedResult from markdown
|
||||
* @param mdStringArg
|
||||
*/
|
||||
public async markdownToHtml(mdString: string): Promise<string> {
|
||||
const result = await plugins
|
||||
.remark()
|
||||
.use(plugins.remarkHtml)
|
||||
.use(plugins.remarkFrontmatter, ['yaml', 'toml'])
|
||||
.process(mdString);
|
||||
return result.toString();
|
||||
}
|
||||
public async getMdParsedResultFromMarkdown(mdStringArg: string): Promise<MdParsedResult> {
|
||||
const result = await MdParsedResult.createFromMarkdownString(mdStringArg);
|
||||
return result;
|
||||
};
|
||||
|
||||
public htmlToMarkdown(htmlString: string): string {
|
||||
const turndownInstance = new plugins.turndown({
|
||||
|
38
ts/smartmarkdown.classes.mdparsedresult.ts
Normal file
38
ts/smartmarkdown.classes.mdparsedresult.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import * as plugins from './smartmarkdown.plugins.js';
|
||||
|
||||
export class MdParsedResult {
|
||||
public static async createFromMarkdownString(mdStringArg: string): Promise<MdParsedResult> {
|
||||
const mdParsedResult = new MdParsedResult();
|
||||
await mdParsedResult.updateFromMarkdownString(mdStringArg);
|
||||
return mdParsedResult;
|
||||
}
|
||||
|
||||
public originalString: string;
|
||||
public title: string;
|
||||
public html: string;
|
||||
public frontmatterData: {[key: string]: any};
|
||||
|
||||
public async updateFromMarkdownString(mdStringArg: string) {
|
||||
let yamlString: string;
|
||||
const result = await plugins.unified()
|
||||
.use(plugins.remarkParse)
|
||||
.use(plugins.remarkGfm)
|
||||
.use(plugins.remarkFrontmatter, ['yaml', 'toml'])
|
||||
.use(plugins.remarkStringify)
|
||||
.use(plugins.remarkHtml)
|
||||
.use(() => (tree) => {
|
||||
console.dir(tree);
|
||||
const yamlChild = tree.children.find(objectArg => objectArg.type === 'yaml');
|
||||
if (yamlChild) {
|
||||
yamlString = (yamlChild as any).value;
|
||||
}
|
||||
})
|
||||
.process(mdStringArg);
|
||||
this.html = result.toString();
|
||||
if (yamlString) {
|
||||
this.frontmatterData = await plugins.smartyaml.yamlStringToObject(yamlString);
|
||||
} else {
|
||||
this.frontmatterData = {};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,19 @@
|
||||
// pushrocks scope
|
||||
import * as smartyaml from '@pushrocks/smartyaml';
|
||||
|
||||
export {
|
||||
smartyaml
|
||||
}
|
||||
|
||||
// third party remark
|
||||
import remark from 'remark';
|
||||
import { unified } from 'unified';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
import remarkParse from 'remark-parse';
|
||||
import remarkFrontmatter from 'remark-frontmatter';
|
||||
import remarkHtml from 'remark-html';
|
||||
import remarkStringify from 'remark-stringify';
|
||||
|
||||
export { remark, remarkFrontmatter, remarkHtml };
|
||||
export { unified, remarkGfm, remarkParse, remarkFrontmatter, remarkHtml, remarkStringify };
|
||||
|
||||
// other third party stuff
|
||||
import turndown from 'turndown';
|
||||
|
9
tsconfig.json
Normal file
9
tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext"
|
||||
}
|
||||
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Reference in New Issue
Block a user