| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c57dabe commit 3c62663
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -738,28 +738,39 @@ function looksLikeAVFileValue(value) { | |||
| 738 | 738 | return typeof value === 'string' || isBuffer(value) | |
| 739 | 739 | } | |
| 740 | 740 | ||
| 741 | + const emptyOptions = {}; | ||
| 741 | 742 | function toString(value, options) { | |
| 742 | - const includeImageAlt = (options || {}).includeImageAlt; | ||
| 743 | - return one( | ||
| 744 | - value, | ||
| 745 | - typeof includeImageAlt === 'boolean' ? includeImageAlt : true | ||
| 746 | - ) | ||
| 743 | + const settings = options || emptyOptions; | ||
| 744 | + const includeImageAlt = | ||
| 745 | + typeof settings.includeImageAlt === 'boolean' | ||
| 746 | + ? settings.includeImageAlt | ||
| 747 | + : true; | ||
| 748 | + const includeHtml = | ||
| 749 | + typeof settings.includeHtml === 'boolean' ? settings.includeHtml : true; | ||
| 750 | + return one(value, includeImageAlt, includeHtml) | ||
| 747 | 751 | } | |
| 748 | - function one(value, includeImageAlt) { | ||
| 749 | - return ( | ||
| 750 | - (node(value) && | ||
| 751 | - (('value' in value && value.value) || | ||
| 752 | - (includeImageAlt && 'alt' in value && value.alt) || | ||
| 753 | - ('children' in value && all(value.children, includeImageAlt)))) || | ||
| 754 | - (Array.isArray(value) && all(value, includeImageAlt)) || | ||
| 755 | - '' | ||
| 756 | - ) | ||
| 752 | + function one(value, includeImageAlt, includeHtml) { | ||
| 753 | + if (node(value)) { | ||
| 754 | + if ('value' in value) { | ||
| 755 | + return value.type === 'html' && !includeHtml ? '' : value.value | ||
| 756 | + } | ||
| 757 | + if (includeImageAlt && 'alt' in value && value.alt) { | ||
| 758 | + return value.alt | ||
| 759 | + } | ||
| 760 | + if ('children' in value) { | ||
| 761 | + return all(value.children, includeImageAlt, includeHtml) | ||
| 762 | + } | ||
| 763 | + } | ||
| 764 | + if (Array.isArray(value)) { | ||
| 765 | + return all(value, includeImageAlt, includeHtml) | ||
| 766 | + } | ||
| 767 | + return '' | ||
| 757 | 768 | } | |
| 758 | - function all(values, includeImageAlt) { | ||
| 769 | + function all(values, includeImageAlt, includeHtml) { | ||
| 759 | 770 | const result = []; | |
| 760 | 771 | let index = -1; | |
| 761 | 772 | while (++index < values.length) { | |
| 762 | - result[index] = one(values[index], includeImageAlt); | ||
| 773 | + result[index] = one(values[index], includeImageAlt, includeHtml); | ||
| 763 | 774 | } | |
| 764 | 775 | return result.join('') | |
| 765 | 776 | } | |
@@ -9827,7 +9838,7 @@ function tokenizePotentialGfmFootnoteCall(effects, ok, nok) { | |||
| 9827 | 9838 | end: self.now() | |
| 9828 | 9839 | }) | |
| 9829 | 9840 | ); | |
| 9830 | - if (id.charCodeAt(0) !== 94 || !defined.includes(id.slice(1))) { | ||
| 9841 | + if (id.codePointAt(0) !== 94 || !defined.includes(id.slice(1))) { | ||
| 9831 | 9842 | return nok(code) | |
| 9832 | 9843 | } | |
| 9833 | 9844 | effects.enter('gfmFootnoteCallLabelMarker'); | |
@@ -9915,24 +9926,32 @@ function tokenizeGfmFootnoteCall(effects, ok, nok) { | |||
| 9915 | 9926 | return callData | |
| 9916 | 9927 | } | |
| 9917 | 9928 | function callData(code) { | |
| 9918 | - let token; | ||
| 9919 | - if (code === null || code === 91 || size++ > 999) { | ||
| 9929 | + if ( | ||
| 9930 | + size > 999 || | ||
| 9931 | + (code === 93 && !data) || | ||
| 9932 | + code === null || | ||
| 9933 | + code === 91 || | ||
| 9934 | + markdownLineEndingOrSpace(code) | ||
| 9935 | + ) { | ||
| 9920 | 9936 | return nok(code) | |
| 9921 | 9937 | } | |
| 9922 | 9938 | if (code === 93) { | |
| 9923 | - if (!data) { | ||
| 9939 | + effects.exit('chunkString'); | ||
| 9940 | + const token = effects.exit('gfmFootnoteCallString'); | ||
| 9941 | + if (!defined.includes(normalizeIdentifier(self.sliceSerialize(token)))) { | ||
| 9924 | 9942 | return nok(code) | |
| 9925 | 9943 | } | |
| 9926 | - effects.exit('chunkString'); | ||
| 9927 | - token = effects.exit('gfmFootnoteCallString'); | ||
| 9928 | - return defined.includes(normalizeIdentifier(self.sliceSerialize(token))) | ||
| 9929 | - ? end(code) | ||
| 9930 | - : nok(code) | ||
| 9944 | + effects.enter('gfmFootnoteCallLabelMarker'); | ||
| 9945 | + effects.consume(code); | ||
| 9946 | + effects.exit('gfmFootnoteCallLabelMarker'); | ||
| 9947 | + effects.exit('gfmFootnoteCall'); | ||
| 9948 | + return ok | ||
| 9931 | 9949 | } | |
| 9932 | - effects.consume(code); | ||
| 9933 | 9950 | if (!markdownLineEndingOrSpace(code)) { | |
| 9934 | 9951 | data = true; | |
| 9935 | 9952 | } | |
| 9953 | + size++; | ||
| 9954 | + effects.consume(code); | ||
| 9936 | 9955 | return code === 92 ? callEscape : callData | |
| 9937 | 9956 | } | |
| 9938 | 9957 | function callEscape(code) { | |
@@ -9943,13 +9962,6 @@ function tokenizeGfmFootnoteCall(effects, ok, nok) { | |||
| 9943 | 9962 | } | |
| 9944 | 9963 | return callData(code) | |
| 9945 | 9964 | } | |
| 9946 | - function end(code) { | ||
| 9947 | - effects.enter('gfmFootnoteCallLabelMarker'); | ||
| 9948 | - effects.consume(code); | ||
| 9949 | - effects.exit('gfmFootnoteCallLabelMarker'); | ||
| 9950 | - effects.exit('gfmFootnoteCall'); | ||
| 9951 | - return ok | ||
| 9952 | - } | ||
| 9953 | 9965 | } | |
| 9954 | 9966 | function tokenizeDefinitionStart(effects, ok, nok) { | |
| 9955 | 9967 | const self = this; | |
@@ -9964,84 +9976,71 @@ function tokenizeDefinitionStart(effects, ok, nok) { | |||
| 9964 | 9976 | effects.enter('gfmFootnoteDefinitionLabelMarker'); | |
| 9965 | 9977 | effects.consume(code); | |
| 9966 | 9978 | effects.exit('gfmFootnoteDefinitionLabelMarker'); | |
| 9967 | - return labelStart | ||
| 9979 | + return labelAtMarker | ||
| 9968 | 9980 | } | |
| 9969 | - function labelStart(code) { | ||
| 9981 | + function labelAtMarker(code) { | ||
| 9970 | 9982 | if (code === 94) { | |
| 9971 | 9983 | effects.enter('gfmFootnoteDefinitionMarker'); | |
| 9972 | 9984 | effects.consume(code); | |
| 9973 | 9985 | effects.exit('gfmFootnoteDefinitionMarker'); | |
| 9974 | 9986 | effects.enter('gfmFootnoteDefinitionLabelString'); | |
| 9975 | - return atBreak | ||
| 9987 | + effects.enter('chunkString').contentType = 'string'; | ||
| 9988 | + return labelInside | ||
| 9976 | 9989 | } | |
| 9977 | 9990 | return nok(code) | |
| 9978 | 9991 | } | |
| 9979 | - function atBreak(code) { | ||
| 9980 | - let token; | ||
| 9981 | - if (code === null || code === 91 || size > 999) { | ||
| 9992 | + function labelInside(code) { | ||
| 9993 | + if ( | ||
| 9994 | + size > 999 || | ||
| 9995 | + (code === 93 && !data) || | ||
| 9996 | + code === null || | ||
| 9997 | + code === 91 || | ||
| 9998 | + markdownLineEndingOrSpace(code) | ||
| 9999 | + ) { | ||
| 9982 | 10000 | return nok(code) | |
| 9983 | 10001 | } | |
| 9984 | 10002 | if (code === 93) { | |
| 9985 | - if (!data) { | ||
| 9986 | - return nok(code) | ||
| 9987 | - } | ||
| 9988 | - token = effects.exit('gfmFootnoteDefinitionLabelString'); | ||
| 10003 | + effects.exit('chunkString'); | ||
| 10004 | + const token = effects.exit('gfmFootnoteDefinitionLabelString'); | ||
| 9989 | 10005 | identifier = normalizeIdentifier(self.sliceSerialize(token)); | |
| 9990 | 10006 | effects.enter('gfmFootnoteDefinitionLabelMarker'); | |
| 9991 | 10007 | effects.consume(code); | |
| 9992 | 10008 | effects.exit('gfmFootnoteDefinitionLabelMarker'); | |
| 9993 | 10009 | effects.exit('gfmFootnoteDefinitionLabel'); | |
| 9994 | 10010 | return labelAfter | |
| 9995 | 10011 | } | |
| 9996 | - if (markdownLineEnding(code)) { | ||
| 9997 | - effects.enter('lineEnding'); | ||
| 9998 | - effects.consume(code); | ||
| 9999 | - effects.exit('lineEnding'); | ||
| 10000 | - size++; | ||
| 10001 | - return atBreak | ||
| 10002 | - } | ||
| 10003 | - effects.enter('chunkString').contentType = 'string'; | ||
| 10004 | - return label(code) | ||
| 10005 | - } | ||
| 10006 | - function label(code) { | ||
| 10007 | - if ( | ||
| 10008 | - code === null || | ||
| 10009 | - markdownLineEnding(code) || | ||
| 10010 | - code === 91 || | ||
| 10011 | - code === 93 || | ||
| 10012 | - size > 999 | ||
| 10013 | - ) { | ||
| 10014 | - effects.exit('chunkString'); | ||
| 10015 | - return atBreak(code) | ||
| 10016 | - } | ||
| 10017 | 10012 | if (!markdownLineEndingOrSpace(code)) { | |
| 10018 | 10013 | data = true; | |
| 10019 | 10014 | } | |
| 10020 | 10015 | size++; | |
| 10021 | 10016 | effects.consume(code); | |
| 10022 | - return code === 92 ? labelEscape : label | ||
| 10017 | + return code === 92 ? labelEscape : labelInside | ||
| 10023 | 10018 | } | |
| 10024 | 10019 | function labelEscape(code) { | |
| 10025 | 10020 | if (code === 91 || code === 92 || code === 93) { | |
| 10026 | 10021 | effects.consume(code); | |
| 10027 | 10022 | size++; | |
| 10028 | - return label | ||
| 10023 | + return labelInside | ||
| 10029 | 10024 | } | |
| 10030 | - return label(code) | ||
| 10025 | + return labelInside(code) | ||
| 10031 | 10026 | } | |
| 10032 | 10027 | function labelAfter(code) { | |
| 10033 | 10028 | if (code === 58) { | |
| 10034 | 10029 | effects.enter('definitionMarker'); | |
| 10035 | 10030 | effects.consume(code); | |
| 10036 | 10031 | effects.exit('definitionMarker'); | |
| 10037 | - return factorySpace(effects, done, 'gfmFootnoteDefinitionWhitespace') | ||
| 10032 | + if (!defined.includes(identifier)) { | ||
| 10033 | + defined.push(identifier); | ||
| 10034 | + } | ||
| 10035 | + return factorySpace( | ||
| 10036 | + effects, | ||
| 10037 | + whitespaceAfter, | ||
| 10038 | + 'gfmFootnoteDefinitionWhitespace' | ||
| 10039 | + ) | ||
| 10038 | 10040 | } | |
| 10039 | 10041 | return nok(code) | |
| 10040 | 10042 | } | |
| 10041 | - function done(code) { | ||
| 10042 | - if (!defined.includes(identifier)) { | ||
| 10043 | - defined.push(identifier); | ||
| 10044 | - } | ||
| 10043 | + function whitespaceAfter(code) { | ||
| 10045 | 10044 | return ok(code) | |
| 10046 | 10045 | } | |
| 10047 | 10046 | } | |
@@ -10069,8 +10068,9 @@ function tokenizeIndent(effects, ok, nok) { | |||
| 10069 | 10068 | } | |
| 10070 | 10069 | } | |
| 10071 | 10070 | ||
| 10072 | - function gfmStrikethrough(options = {}) { | ||
| 10073 | - let single = options.singleTilde; | ||
| 10071 | + function gfmStrikethrough(options) { | ||
| 10072 | + const options_ = options || {}; | ||
| 10073 | + let single = options_.singleTilde; | ||
| 10074 | 10074 | const tokenizer = { | |
| 10075 | 10075 | tokenize: tokenizeStrikethrough, | |
| 10076 | 10076 | resolveAll: resolveAllStrikethrough | |
@@ -10124,16 +10124,15 @@ function gfmStrikethrough(options = {}) { | |||
| 10124 | 10124 | ['exit', events[open][1], context], | |
| 10125 | 10125 | ['enter', text, context] | |
| 10126 | 10126 | ]; | |
| 10127 | - splice( | ||
| 10128 | - nextEvents, | ||
| 10129 | - nextEvents.length, | ||
| 10130 | - 0, | ||
| 10131 | - resolveAll( | ||
| 10132 | - context.parser.constructs.insideSpan.null, | ||
| 10133 | - events.slice(open + 1, index), | ||
| 10134 | - context | ||
| 10135 | - ) | ||
| 10136 | - ); | ||
| 10127 | + const insideSpan = context.parser.constructs.insideSpan.null; | ||
| 10128 | + if (insideSpan) { | ||
| 10129 | + splice( | ||
| 10130 | + nextEvents, | ||
| 10131 | + nextEvents.length, | ||
| 10132 | + 0, | ||
| 10133 | + resolveAll(insideSpan, events.slice(open + 1, index), context) | ||
| 10134 | + ); | ||
| 10135 | + } | ||
| 10137 | 10136 | splice(nextEvents, nextEvents.length, 0, [ | |
| 10138 | 10137 | ['exit', text, context], | |
| 10139 | 10138 | ['enter', events[index][1], context], | |
@@ -10673,29 +10672,30 @@ function tokenizeTasklistCheck(effects, ok, nok) { | |||
| 10673 | 10672 | effects.consume(code); | |
| 10674 | 10673 | effects.exit('taskListCheckMarker'); | |
| 10675 | 10674 | effects.exit('taskListCheck'); | |
| 10675 | + return after | ||
| 10676 | + } | ||
| 10677 | + return nok(code) | ||
| 10678 | + } | ||
| 10679 | + function after(code) { | ||
| 10680 | + if (markdownLineEnding(code)) { | ||
| 10681 | + return ok(code) | ||
| 10682 | + } | ||
| 10683 | + if (markdownSpace(code)) { | ||
| 10676 | 10684 | return effects.check( | |
| 10677 | 10685 | { | |
| 10678 | 10686 | tokenize: spaceThenNonSpace | |
| 10679 | 10687 | }, | |
| 10680 | 10688 | ok, | |
| 10681 | 10689 | nok | |
| 10682 | - ) | ||
| 10690 | + )(code) | ||
| 10683 | 10691 | } | |
| 10684 | 10692 | return nok(code) | |
| 10685 | 10693 | } | |
| 10686 | 10694 | } | |
| 10687 | 10695 | function spaceThenNonSpace(effects, ok, nok) { | |
| 10688 | - const self = this; | ||
| 10689 | 10696 | return factorySpace(effects, after, 'whitespace') | |
| 10690 | 10697 | function after(code) { | |
| 10691 | - const tail = self.events[self.events.length - 1]; | ||
| 10692 | - return ( | ||
| 10693 | - ((tail && tail[1].type === 'whitespace') || | ||
| 10694 | - markdownLineEnding(code)) && | ||
| 10695 | - code !== null | ||
| 10696 | - ? ok(code) | ||
| 10697 | - : nok(code) | ||
| 10698 | - ) | ||
| 10698 | + return code === null ? nok(code) : ok(code) | ||
| 10699 | 10699 | } | |
| 10700 | 10700 | } | |
| 10701 | 10701 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments