Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor Testing] Refactoring from parser.
- Loading branch information
1 parent
b209979
commit 2fb9a9e
Showing
23 changed files
with
131 additions
and
687 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.