Skip to content

Commit

Permalink
[Filter] Add handler tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
aquariuslt committed Oct 18, 2017
1 parent c9e17ed commit fb82577
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/shared/marki.context.ts
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions 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);
});
});

});
});

0 comments on commit fb82577

Please sign in to comment.