|
1 |
| -function replaceMarkdown(regexp, callback) { |
2 |
| - // console.log('helpers- replace markdown method') |
3 |
| - // console.log(typeof callback) |
4 |
| - |
5 |
| - let fixedCallbackMethod = false; |
6 |
| - switch (typeof callback) { |
7 |
| - case 'string': |
8 |
| - fixedCallbackMethod = callback; |
9 |
| - break; |
10 |
| - |
11 |
| - case 'undefined': |
12 |
| - console.log("ERRROROROR HERE!!!!"); |
13 |
| - console.log(regexp) |
14 |
| - console.log(callback) |
15 |
| - |
16 |
| - break; |
17 |
| - |
18 |
| - default: |
19 |
| - fixedCallbackMethod = callback.bind(this); |
20 |
| - break; |
21 |
| - } |
22 |
| - |
23 |
| - this.content = this.content.replace(regexp, fixedCallbackMethod); |
24 |
| -} |
25 |
| - |
26 |
| -// @TODO find out if we really using this method or not? |
27 |
| -function replaceMarkdownPreviewText(regexp) { |
28 |
| - const config = { |
29 |
| - content: this.content.trim(), |
30 |
| - }; |
31 |
| - |
32 |
| - /* |
33 |
| - this.previewText = replaceWrapper( |
34 |
| - "previewText", |
35 |
| - config, |
36 |
| - "body" |
37 |
| - ); |
38 |
| - console.log(this.previewText) |
39 |
| - */ |
40 |
| - |
41 |
| - |
42 |
| - this.errors.previewText = true; |
43 |
| - |
44 |
| - this.content = this.content.replace( |
45 |
| - regexp, |
46 |
| - () => this.previewText, |
47 |
| - ); |
48 |
| -} |
49 |
| - |
50 |
| -// TODO update this method. I'm sure it can be improved. |
51 |
| -function __parse(source) { |
52 |
| - // passing content into the state, |
53 |
| - // so we can do our updates step by step and track any errors |
54 |
| - const state = stateInit(source); |
55 |
| - |
56 |
| - Replacer.replaceMDBinded = replaceMarkdown.bind(state); |
57 |
| - Replacer.replaceMDBindedPreviewText = replaceMarkdownPreviewText.bind(state); |
58 |
| - |
59 |
| - Replacer.previewText(); |
60 |
| - Replacer.replaceMDBindedPreviewText(REGEXP_PREVIEW_TEXT); |
61 |
| - Replacer.comments(); |
62 |
| - |
63 |
| - Replacer.strong(); |
64 |
| - Replacer.em(); |
65 |
| - Replacer.header(); |
66 |
| - Replacer.image(); |
67 |
| - Replacer.link(); |
68 |
| - Replacer.del(); |
69 |
| - Replacer.q(); |
70 |
| - Replacer.code(); |
71 |
| - Replacer.ul(); |
72 |
| - Replacer.ol(); |
73 |
| - Replacer.blockquote(); |
74 |
| - Replacer.hr(); |
75 |
| - Replacer.paragraph(); |
76 |
| - Replacer.emptyUl(); |
77 |
| - Replacer.emptyOl(); |
78 |
| - |
79 |
| - // this line is generating an error |
80 |
| - Replacer.emptyBlockquote(); |
81 |
| - Replacer.br(); |
82 |
| - |
83 |
| - if (!process.env.PARSE === 'noAdv' || process.env.PARSE === 'full') { |
84 |
| - Replacer.sponsorship(); |
85 |
| - } |
86 |
| - |
87 |
| - Replacer.memes(); |
88 |
| - Replacer.separator(); |
89 |
| - |
90 |
| - // i'm adding it only because error warning didnt return red stuff |
91 |
| - // checkErrors(state.errors); |
92 |
| - state.innerCheckErrors(); |
93 |
| - |
94 |
| - // console.log(state) |
95 |
| - |
96 |
| - return state; |
97 |
| -} |
98 |
| - |
99 |
| -module.exports = { |
100 |
| - replaceMarkdown, |
101 |
| - replaceMarkdownPreviewText, |
102 |
| -}; |
| 1 | +function replaceMarkdown(regexp, callback) { |
| 2 | + // console.log('helpers- replace markdown method') |
| 3 | + // console.log(typeof callback) |
| 4 | + |
| 5 | + let fixedCallbackMethod = false; |
| 6 | + switch (typeof callback) { |
| 7 | + case 'string': |
| 8 | + fixedCallbackMethod = callback; |
| 9 | + break; |
| 10 | + |
| 11 | + case 'undefined': |
| 12 | + console.log('ERRROROROR HERE!!!!'); |
| 13 | + console.log(regexp); |
| 14 | + console.log(callback); |
| 15 | + |
| 16 | + break; |
| 17 | + |
| 18 | + default: |
| 19 | + fixedCallbackMethod = callback.bind(this); |
| 20 | + break; |
| 21 | + } |
| 22 | + |
| 23 | + this.content = this.content.replace(regexp, fixedCallbackMethod); |
| 24 | +} |
| 25 | + |
| 26 | +// @TODO find out if we really using this method or not? |
| 27 | +function replaceMarkdownPreviewText(regexp) { |
| 28 | + const config = { |
| 29 | + content: this.content.trim(), |
| 30 | + }; |
| 31 | + |
| 32 | + /* |
| 33 | + this.previewText = replaceWrapper( |
| 34 | + "previewText", |
| 35 | + config, |
| 36 | + "body" |
| 37 | + ); |
| 38 | + console.log(this.previewText) |
| 39 | + */ |
| 40 | + |
| 41 | + this.errors.previewText = true; |
| 42 | + |
| 43 | + this.content = this.content.replace(regexp, () => this.previewText); |
| 44 | +} |
| 45 | + |
| 46 | +// TODO update this method. I'm sure it can be improved. |
| 47 | +function __parse(source) { |
| 48 | + // passing content into the state, |
| 49 | + // so we can do our updates step by step and track any errors |
| 50 | + const state = stateInit(source); |
| 51 | + |
| 52 | + Replacer.replaceMDBinded = replaceMarkdown.bind(state); |
| 53 | + Replacer.replaceMDBindedPreviewText = replaceMarkdownPreviewText.bind(state); |
| 54 | + |
| 55 | + Replacer.previewText(); |
| 56 | + Replacer.replaceMDBindedPreviewText(REGEXP_PREVIEW_TEXT); |
| 57 | + Replacer.comments(); |
| 58 | + |
| 59 | + Replacer.strong(); |
| 60 | + Replacer.em(); |
| 61 | + Replacer.header(); |
| 62 | + Replacer.image(); |
| 63 | + Replacer.link(); |
| 64 | + Replacer.del(); |
| 65 | + Replacer.q(); |
| 66 | + Replacer.code(); |
| 67 | + Replacer.ul(); |
| 68 | + Replacer.ol(); |
| 69 | + Replacer.blockquote(); |
| 70 | + Replacer.hr(); |
| 71 | + Replacer.paragraph(); |
| 72 | + Replacer.emptyUl(); |
| 73 | + Replacer.emptyOl(); |
| 74 | + |
| 75 | + // this line is generating an error |
| 76 | + Replacer.emptyBlockquote(); |
| 77 | + Replacer.br(); |
| 78 | + |
| 79 | + if (!process.env.PARSE === 'noAdv' || process.env.PARSE === 'full') { |
| 80 | + Replacer.sponsorship(); |
| 81 | + } |
| 82 | + |
| 83 | + Replacer.memes(); |
| 84 | + Replacer.separator(); |
| 85 | + |
| 86 | + // i'm adding it only because error warning didnt return red stuff |
| 87 | + // checkErrors(state.errors); |
| 88 | + state.innerCheckErrors(); |
| 89 | + |
| 90 | + // console.log(state) |
| 91 | + |
| 92 | + return state; |
| 93 | +} |
| 94 | + |
| 95 | +module.exports = { |
| 96 | + replaceMarkdown, |
| 97 | + replaceMarkdownPreviewText, |
| 98 | +}; |
0 commit comments