@@ -22,87 +22,93 @@ import {parseEntities} from 'parse-entities'
22
22
import { stringifyEntitiesLight } from 'stringify-entities'
23
23
import { visitParents } from 'unist-util-visit-parents'
24
24
25
- // To do: next major: expose functions.
26
-
27
25
const own = { } . hasOwnProperty
28
26
29
27
const shortcut = / ^ [ ^ \t \n \r " # ' . < = > ` } ] + $ /
30
28
31
29
handleDirective . peek = peekDirective
32
30
33
31
/**
34
- * Extension for `mdast-util-from-markdown` to enable directives.
32
+ * Create an extension for `mdast-util-from-markdown` to enable directives in
33
+ * markdown.
35
34
*
36
- * @type {FromMarkdownExtension }
35
+ * @returns {FromMarkdownExtension }
36
+ * Extension for `mdast-util-from-markdown` to enable directives.
37
37
*/
38
- export const directiveFromMarkdown = {
39
- canContainEols : [ 'textDirective' ] ,
40
- enter : {
41
- directiveContainer : enterContainer ,
42
- directiveContainerAttributes : enterAttributes ,
43
- directiveContainerLabel : enterContainerLabel ,
44
-
45
- directiveLeaf : enterLeaf ,
46
- directiveLeafAttributes : enterAttributes ,
47
-
48
- directiveText : enterText ,
49
- directiveTextAttributes : enterAttributes
50
- } ,
51
- exit : {
52
- directiveContainer : exit ,
53
- directiveContainerAttributeClassValue : exitAttributeClassValue ,
54
- directiveContainerAttributeIdValue : exitAttributeIdValue ,
55
- directiveContainerAttributeName : exitAttributeName ,
56
- directiveContainerAttributeValue : exitAttributeValue ,
57
- directiveContainerAttributes : exitAttributes ,
58
- directiveContainerLabel : exitContainerLabel ,
59
- directiveContainerName : exitName ,
60
-
61
- directiveLeaf : exit ,
62
- directiveLeafAttributeClassValue : exitAttributeClassValue ,
63
- directiveLeafAttributeIdValue : exitAttributeIdValue ,
64
- directiveLeafAttributeName : exitAttributeName ,
65
- directiveLeafAttributeValue : exitAttributeValue ,
66
- directiveLeafAttributes : exitAttributes ,
67
- directiveLeafName : exitName ,
68
-
69
- directiveText : exit ,
70
- directiveTextAttributeClassValue : exitAttributeClassValue ,
71
- directiveTextAttributeIdValue : exitAttributeIdValue ,
72
- directiveTextAttributeName : exitAttributeName ,
73
- directiveTextAttributeValue : exitAttributeValue ,
74
- directiveTextAttributes : exitAttributes ,
75
- directiveTextName : exitName
38
+ export function directiveFromMarkdown ( ) {
39
+ return {
40
+ canContainEols : [ 'textDirective' ] ,
41
+ enter : {
42
+ directiveContainer : enterContainer ,
43
+ directiveContainerAttributes : enterAttributes ,
44
+ directiveContainerLabel : enterContainerLabel ,
45
+
46
+ directiveLeaf : enterLeaf ,
47
+ directiveLeafAttributes : enterAttributes ,
48
+
49
+ directiveText : enterText ,
50
+ directiveTextAttributes : enterAttributes
51
+ } ,
52
+ exit : {
53
+ directiveContainer : exit ,
54
+ directiveContainerAttributeClassValue : exitAttributeClassValue ,
55
+ directiveContainerAttributeIdValue : exitAttributeIdValue ,
56
+ directiveContainerAttributeName : exitAttributeName ,
57
+ directiveContainerAttributeValue : exitAttributeValue ,
58
+ directiveContainerAttributes : exitAttributes ,
59
+ directiveContainerLabel : exitContainerLabel ,
60
+ directiveContainerName : exitName ,
61
+
62
+ directiveLeaf : exit ,
63
+ directiveLeafAttributeClassValue : exitAttributeClassValue ,
64
+ directiveLeafAttributeIdValue : exitAttributeIdValue ,
65
+ directiveLeafAttributeName : exitAttributeName ,
66
+ directiveLeafAttributeValue : exitAttributeValue ,
67
+ directiveLeafAttributes : exitAttributes ,
68
+ directiveLeafName : exitName ,
69
+
70
+ directiveText : exit ,
71
+ directiveTextAttributeClassValue : exitAttributeClassValue ,
72
+ directiveTextAttributeIdValue : exitAttributeIdValue ,
73
+ directiveTextAttributeName : exitAttributeName ,
74
+ directiveTextAttributeValue : exitAttributeValue ,
75
+ directiveTextAttributes : exitAttributes ,
76
+ directiveTextName : exitName
77
+ }
76
78
}
77
79
}
78
80
79
81
/**
80
- * Extension for `mdast-util-to-markdown` to enable directives.
82
+ * Create an extension for `mdast-util-to-markdown` to enable directives in
83
+ * markdown.
81
84
*
82
- * @type {ToMarkdownExtension }
85
+ * @returns {ToMarkdownExtension }
86
+ * Extension for `mdast-util-to-markdown` to enable directives.
83
87
*/
84
- export const directiveToMarkdown = {
85
- unsafe : [
86
- {
87
- character : '\r' ,
88
- inConstruct : [ 'leafDirectiveLabel' , 'containerDirectiveLabel' ]
89
- } ,
90
- {
91
- character : '\n' ,
92
- inConstruct : [ 'leafDirectiveLabel' , 'containerDirectiveLabel' ]
93
- } ,
94
- {
95
- before : '[^:]' ,
96
- character : ':' ,
97
- after : '[A-Za-z]' ,
98
- inConstruct : [ 'phrasing' ]
99
- } ,
100
- { atBreak : true , character : ':' , after : ':' }
101
- ] ,
102
- handlers : {
103
- containerDirective : handleDirective ,
104
- leafDirective : handleDirective ,
105
- textDirective : handleDirective
88
+ export function directiveToMarkdown ( ) {
89
+ return {
90
+ unsafe : [
91
+ {
92
+ character : '\r' ,
93
+ inConstruct : [ 'leafDirectiveLabel' , 'containerDirectiveLabel' ]
94
+ } ,
95
+ {
96
+ character : '\n' ,
97
+ inConstruct : [ 'leafDirectiveLabel' , 'containerDirectiveLabel' ]
98
+ } ,
99
+ {
100
+ before : '[^:]' ,
101
+ character : ':' ,
102
+ after : '[A-Za-z]' ,
103
+ inConstruct : [ 'phrasing' ]
104
+ } ,
105
+ { atBreak : true , character : ':' , after : ':' }
106
+ ] ,
107
+ handlers : {
108
+ containerDirective : handleDirective ,
109
+ leafDirective : handleDirective ,
110
+ textDirective : handleDirective
111
+ }
106
112
}
107
113
}
108
114
0 commit comments