BREAKING CHANGE(core): switch to class based design and support html to markdown

This commit is contained in:
Philipp Kunz 2019-06-17 11:56:39 +02:00
parent a66e795432
commit 1361e825fe
7 changed files with 1104 additions and 142 deletions

18
.gitignore vendored
View File

@ -1,6 +1,22 @@
.nogit/
node_modules/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom

View File

@ -1,4 +1,4 @@
# gitzone standard
# gitzone ci_default
image: hosttoday/ht-docker-node:npmci
cache:
@ -78,19 +78,11 @@ release:
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SOURCE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
- npmci command npm install -g tslint typescript
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
@ -109,10 +101,10 @@ pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g typedoc typescript
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
- npmci command tsdoc
tags:
- docker
- notpriv

1141
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -14,12 +14,26 @@
"devDependencies": {
"@gitzone/tsbuild": "^2.1.11",
"@gitzone/tsrun": "^1.2.6",
"@gitzone/tstest": "^1.0.20",
"@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.9",
"@types/node": "^12.0.0"
"@types/node": "^12.0.8",
"tslint": "^5.17.0",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@types/marked": "^0.6.5",
"marked": "^0.6.2"
}
}
"@types/turndown": "^5.0.0",
"marked": "^0.6.2",
"turndown": "^5.0.3"
},
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"assets/*",
"cli.js",
"npmextra.json",
"readme.md"
]
}

View File

@ -1,9 +1,23 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartmarkdown from '../ts/index';
tap.test('first test', async () => {
const mdString = smartmarkdown.markdownToHtml('# Hi!');
expect(mdString).to.equal('<h1 id="hi">Hi!</h1>\n');
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);
});
tap.test('should convert a markdown string to html', async () => {
const markdownString = '# Hi!';
const htmlString = smartMarkdownInstance.markdownToHtml(markdownString);
expect(htmlString).to.equal('<h1 id="hi">Hi!</h1>\n');
});
tap.test('should convert a html string to markdown', async () => {
const htmlString = '<h1 id="hi">Hi!</h1>\n<h2>This is it!</h2>';
const markdownString = smartMarkdownInstance.htmlToMarkdown(htmlString);
console.log(markdownString);
});
tap.start();

View File

@ -1,3 +1,21 @@
import * as plugins from './smartmarkdown.plugins';
export const markdownToHtml = (mdString: string): string => plugins.marked(mdString);
export class SmartMarkdown {
constructor() {}
/**
* converts markdown to html
* @param mdString
*/
public markdownToHtml(mdString: string): string {
return plugins.marked(mdString);
}
public htmlToMarkdown(htmlString): string {
const turndownInstance = new plugins.turndown({
headingStyle: 'atx',
codeBlockStyle: 'fenced'
});
return turndownInstance.turndown(htmlString);
}
}

View File

@ -1,3 +1,4 @@
import marked = require('marked');
import turndown from 'turndown';
export { marked };
export { marked, turndown };