diff --git a/src/shared/marki.context.ts b/src/shared/marki.context.ts index f23fb3d..591f083 100644 --- a/src/shared/marki.context.ts +++ b/src/shared/marki.context.ts @@ -41,11 +41,11 @@ export default class MarkiContext { let lexer = new marked.Lexer(); $this.tokens = lexer.lex(source); - $this.doFilter(); + $this.doCodeFilter(); $this.doHandleCustomizeCodeType(); } - private doFilter() { + private doCodeFilter() { let $this = this; _.each($this.codeFilters, function (needFilteredCode) { @@ -69,18 +69,26 @@ export default class MarkiContext { } private doHandleCustomizeCodeType() { - // perform pre-handle - // perform handle + let $this = this; + + let groupByLanguageCodeHandlers = _.groupBy($this.codeHandlers,function (handler) { + return handler.language; + }); + + + _.each($this.needHandleTokens,function (token) { + + }); } /* export level functions */ - addCodeFilters(filterCode: CodeFilter) { + public addCodeFilters(filterCode: CodeFilter) { let $this = this; $this.codeFilters.push(filterCode); } - addCodeHandlers(language: string, handlerFn: Function) { + public addCodeHandlers(language: string, handlerFn: Function) { let $this = this; $this.codeHandlers.push({ language: language, diff --git a/test/unit/specs/codefilter.spec.js b/test/unit/specs/code-filter.spec.js similarity index 100% rename from test/unit/specs/codefilter.spec.js rename to test/unit/specs/code-filter.spec.js diff --git a/test/unit/specs/code-handler.spec.js b/test/unit/specs/code-handler.spec.js new file mode 100644 index 0000000..9563a66 --- /dev/null +++ b/test/unit/specs/code-handler.spec.js @@ -0,0 +1,30 @@ +import * as marked from 'marked'; +import MarkiContext from '@/shared/marki.context'; + +import mdStringWithMetadataCodeType from '../data/post-with-metadata.md'; + +describe('code handler', function() { + + + describe('metadata handler',function() { + let $this = this; + $this.marki = new MarkiContext(); + + + beforeEach('# add metadata filter',function() { + $this.marki = new MarkiContext(); + $this.marki.addCodeFilters({ + language: 'metadata', + handle: true + }); + + }); + + it('# handler: metadata', function() { + $this.marki.addCodeHandlers('metadata',function(markiContext,singleToken) { + console.log('try log single token:',singleToken); + }); + }); + + }); +});