Skip to content

Commit

Permalink
[Refactor Testing] Refactoring from parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
aquariuslt committed Oct 3, 2017
1 parent b209979 commit 2fb9a9e
Show file tree
Hide file tree
Showing 23 changed files with 131 additions and 687 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -54,12 +54,12 @@ customize renderer, I hope marki can help.
#### Code Example

Usage 1, directly using marki bundled transform
```
```javascript
const htmlString = marki(mdString);
```

Usage 2, using marki with options
```
```javascript
let transformOptions = {
lexer:{

Expand All @@ -75,7 +75,7 @@ const htmlString = marki(mdString, transformOptions)
```

Usage 3, using customize marki wrapper and add customize options.
```
```javascript
let myMdCompiler = new marki.Compiler();
myMdCompiler.parser.set('xxxOptionName',false);
myMdCompiler.parser.set('xxxOptionName','-');
Expand Down
4 changes: 1 addition & 3 deletions package.json
Expand Up @@ -11,9 +11,6 @@
"clean": "gulp clean",
"test": "gulp test"
},
"dependencies": {
"marked": "^0.3.6"
},
"devDependencies": {
"@types/chai": "^4.0.4",
"@types/mocha": "^2.2.43",
Expand Down Expand Up @@ -48,6 +45,7 @@
"karma-spec-reporter": "^0.0.31",
"karma-webpack": "^2.0.4",
"lodash": "^4.17.4",
"marked": "^0.3.6",
"mocha": "^3.5.1",
"mocha-lcov-reporter": "^1.3.0",
"puppeteer": "^0.10.2",
Expand Down
20 changes: 0 additions & 20 deletions src/lexer/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/lexer/lexer.options.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/lexer/rules.d.ts

This file was deleted.

107 changes: 99 additions & 8 deletions src/main.ts
@@ -1,15 +1,106 @@
import Lexer from './lexer';
import Parser from './parser';
import Renderer from './renderer';
import * as marked from 'marked';


export {
Lexer,
Parser,
Renderer
function omarki(source) {
return marked(source);
}


export function marki(){
function marki(source) {
let lexer = new Lexer();
let tokens = lexer.lex(source);
let parser = new Parser();
return parser.parse(tokens);
}


class Lexer {
private blockLexer: BlockLexer;
private inlineLexer: InlineLexer;

constructor() {
let $this = this;
$this.blockLexer = new BlockLexer();
$this.inlineLexer = new InlineLexer();


}


lex(source: string) {
let $this = this;
let tokens = $this.blockLexer.lex(source);
$this.inlineLexer.lexTokens(tokens);
return tokens;
};


}

class BlockLexer {
lex(mdString) {
let markedTokens = new marked.Lexer().lex(mdString);

return new Tokens(markedTokens);
}
}

class InlineLexer {
private inline;

lexTokens(tokens: Tokens) {
let $this = this;
$this.inline = marked.InlineLexer(tokens.links);
}

output(source) {
let $this = this;
return $this.inline.output(source);
}

outputLink(cap, link) {
let $this = this;
return $this.inline.outputLink(cap, link);
}

smartypants(text) {
let $this = this;
return $this.inline.smartypants(text);
}
}


class Token extends Object {
}

class TokenLinks extends Object {
}

class Tokens {
tokens: Array<Token>;
links: TokenLinks;

constructor(markedTokens) {
let $this = this;
$this.links = markedTokens.links;
delete markedTokens.links;
$this.tokens = markedTokens;
}
}

class Parser {
parse(tokens: Tokens) {

let innerTokens = Object(tokens.tokens);
innerTokens.links = tokens.links;

return new marked.Parser().parse(innerTokens);
}
}



export {
omarki,
marki
};
17 changes: 0 additions & 17 deletions src/parser/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/parser/parser.options.ts

This file was deleted.

84 changes: 0 additions & 84 deletions src/renderer/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/renderer/renderer.options.ts

This file was deleted.

Empty file removed src/shared/constants.ts
Empty file.
25 changes: 0 additions & 25 deletions src/shared/token.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/shared/token.types.ts

This file was deleted.

0 comments on commit 2fb9a9e

Please sign in to comment.