Skip to content

Commit

Permalink
Apply named export to internal modules
Browse files Browse the repository at this point in the history
  • Loading branch information
yhatt committed Nov 13, 2022
1 parent 077bb25 commit c845961
Show file tree
Hide file tree
Showing 74 changed files with 301 additions and 250 deletions.
2 changes: 1 addition & 1 deletion src/helpers/postcss_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @param {(Function|Object)} func Function with PostCSS plugin interface.
* @returns {Function} A PostCSS plugin.
*/
function plugin(name, func) {
export function plugin(name, func) {
return Object.defineProperty(
function intrface(...args) {
const retFunc = func.apply(this, args)
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/split.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
/**
* Split array into multiple arrays by specified condition.
*
* @alias module:helpers/split
* @param {Array} arr Target array.
* @param {splitCallback} func Callback to split array.
* @param {boolean} [keepSplitedValue=false] Keep splited value. The split
* point is before the matched value.
* @returns {Array[]} Splited array.
*/
function split(arr, func, keepSplitedValue = false) {
export function split(arr, func, keepSplitedValue = false) {
const ret = [[]]

for (const value of arr) {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/wrap_array.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
/**
* Wrap value in array if it is not an array.
*
* @alias module:helpers/wrap_array
* @function wrapArray
* @param {*} valOrArr
* @return {Array}
*/
const wrapArray = (valOrArr) => {
export const wrapArray = (valOrArr) => {
if (valOrArr == null || valOrArr === false) return []
if (valOrArr instanceof Array) return valOrArr
return [valOrArr]
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/wrap_tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/**
* Wrap array of tokens by specified container object.
*
* @alias module:helpers/wrap_tokens
* @param {Token} Token markdown-it's Token class.
* @param {String} type Token type. It will be suffixed by `_open` / `_close`.
* @param {Object} container A container object to wrap tokens, includes tag
Expand All @@ -14,7 +13,7 @@
* @param {Token[]} [tokens=[]] Wrapping tokens.
* @returns {Token[]} Wrapped tokens.
*/
function wrapTokens(Token, type, container, tokens = []) {
export function wrapTokens(Token, type, container, tokens = []) {
const { tag } = container

// Update nesting level of wrapping tokens
Expand Down
7 changes: 4 additions & 3 deletions src/markdown/background_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import parse from './background_image/parse'
* In addition to the basic background implementation, it supports multiple
* background images, filters, and split background.
*
* @alias module:markdown/background_image
* @function backgroundImage
* @param {MarkdownIt} md markdown-it instance.
*/
function backgroundImage(md) {
function _backgroundImage(md) {
parse(md)
apply(md)
advanced(md)
}

export default marpitPlugin(backgroundImage)
export const backgroundImage = marpitPlugin(_backgroundImage)
export default backgroundImage
9 changes: 5 additions & 4 deletions src/markdown/background_image/advanced.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @module */
import InlineStyle from '../../helpers/inline_style'
import wrapTokens from '../../helpers/wrap_tokens'
import { wrapTokens } from '../../helpers/wrap_tokens'
import marpitPlugin from '../../plugin'

/**
Expand All @@ -10,10 +10,10 @@ import marpitPlugin from '../../plugin'
* element(s) instead of CSS backgrounds. It works by creating the isolated
* layer into inline SVG.
*
* @alias module:markdown/background_image/advanced
* @function advancedBackground
* @param {MarkdownIt} md markdown-it instance.
*/
function advancedBackground(md) {
function _advancedBackground(md) {
md.core.ruler.after(
'marpit_directives_apply',
'marpit_advanced_background',
Expand Down Expand Up @@ -157,4 +157,5 @@ function advancedBackground(md) {
)
}

export default marpitPlugin(advancedBackground)
export const advancedBackground = marpitPlugin(_advancedBackground)
export default advancedBackground
7 changes: 4 additions & 3 deletions src/markdown/background_image/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import marpitPlugin from '../../plugin'
* When inline SVG is enabled, it will reshape meta for advanced process instead
* of converting to directives.
*
* @alias module:markdown/background_image/apply
* @function backgroundImageApply
* @param {MarkdownIt} md markdown-it instance.
*/
function backgroundImageApply(md) {
function _backgroundImageApply(md) {
md.core.ruler.after(
'marpit_inline_svg',
'marpit_apply_background_image',
Expand Down Expand Up @@ -115,4 +115,5 @@ function backgroundImageApply(md) {
)
}

export default marpitPlugin(backgroundImageApply)
export const backgroundImageApply = marpitPlugin(_backgroundImageApply)
export default backgroundImageApply
7 changes: 4 additions & 3 deletions src/markdown/background_image/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const splitSizeMatcher = /^(left|right)(?::((?:\d*\.)?\d+%))?$/
*
* Furthermore, it parses additional keywords needed for background image.
*
* @alias module:markdown/background_image/parse
* @function backgroundImageParse
* @param {MarkdownIt} md markdown-it instance.
*/
function backgroundImageParse(md) {
function _backgroundImageParse(md) {
md.inline.ruler2.after(
'marpit_parse_image',
'marpit_background_image',
Expand Down Expand Up @@ -75,4 +75,5 @@ function backgroundImageParse(md) {
)
}

export default marpitPlugin(backgroundImageParse)
export const backgroundImageParse = marpitPlugin(_backgroundImageParse)
export default backgroundImageParse
7 changes: 4 additions & 3 deletions src/markdown/collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import marpitPlugin from '../plugin'
* Marpit instance. It would use in the returned object from
* {@link Marpit#render}.
*
* @alias module:markdown/collect
* @function collect
* @param {MarkdownIt} md markdown-it instance.
*/
function collect(md) {
function _collect(md) {
const { marpit } = md

md.core.ruler.push('marpit_collect', (state) => {
Expand Down Expand Up @@ -61,4 +61,5 @@ function collect(md) {
})
}

export default marpitPlugin(collect)
export const collect = marpitPlugin(_collect)
export default collect
9 changes: 5 additions & 4 deletions src/markdown/comment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @module */
import marpitPlugin from '../plugin'
import yaml from './directives/yaml'
import { yaml } from './directives/yaml'

const commentMatcher = /<!--+\s*([\s\S]*?)\s*--+>/
const commentMatcherOpening = /^<!--/
Expand Down Expand Up @@ -28,10 +28,10 @@ export function markAsParsed(token, kind) {
* Parse HTML comment as token. Comments will strip regardless of html setting
* provided by markdown-it.
*
* @alias module:markdown/comment
* @function comment
* @param {MarkdownIt} md markdown-it instance.
*/
function comment(md) {
function _comment(md) {
const parse = (token, content) => {
const parsed = yaml(content, !!md.marpit.options.looseYAML)

Expand Down Expand Up @@ -126,4 +126,5 @@ function comment(md) {
)
}

export default marpitPlugin(comment)
export const comment = marpitPlugin(_comment)
export default comment
11 changes: 6 additions & 5 deletions src/markdown/container.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/** @module */
import wrapArray from '../helpers/wrap_array'
import wrapTokens from '../helpers/wrap_tokens'
import { wrapArray } from '../helpers/wrap_array'
import { wrapTokens } from '../helpers/wrap_tokens'
import marpitPlugin from '../plugin'

/**
* Marpit container plugin.
*
* @alias module:markdown/container
* @function container
* @param {MarkdownIt} md markdown-it instance.
*/
function container(md) {
function _container(md) {
const containers = wrapArray(md.marpit.options.container)
if (!containers) return

Expand All @@ -28,4 +28,5 @@ function container(md) {
})
}

export default marpitPlugin(container)
export const container = marpitPlugin(_container)
export default container
7 changes: 4 additions & 3 deletions src/markdown/directives/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import builtInDirectives from './directives'
/**
* Apply parsed Marpit directives to markdown-it tokens.
*
* @alias module:markdown/directives/apply
* @function apply
* @param {MarkdownIt} md markdown-it instance.
* @param {Object} [opts]
* @param {boolean} [opts.dataset=true] Assigns directives as HTML data
* attributes of each section tag.
* @param {boolean} [opts.css=true] Assigns directives as CSS Custom Properties
* of each section tag.
*/
function apply(md, opts = {}) {
function _apply(md, opts = {}) {
const { marpit } = md

const dataset = opts.dataset === undefined ? true : !!opts.dataset
Expand Down Expand Up @@ -103,4 +103,5 @@ function apply(md, opts = {}) {
)
}

export default marpitPlugin(apply)
export const apply = marpitPlugin(_apply)
export default apply
9 changes: 5 additions & 4 deletions src/markdown/directives/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import MarkdownItFrontMatter from 'markdown-it-front-matter'
import marpitPlugin from '../../plugin'
import { markAsParsed } from '../comment'
import * as directives from './directives'
import yaml from './yaml'
import { yaml } from './yaml'

const isDirectiveComment = (token) =>
token.type === 'marpit_comment' && token.meta.marpitParsedDirectives
Expand All @@ -14,14 +14,14 @@ const isDirectiveComment = (token) =>
* Marpit comment plugin ans slide plugin requires already loaded to
* markdown-it instance.
*
* @alias module:markdown/directives/parse
* @function parse
* @param {MarkdownIt} md markdown-it instance.
* @param {Object} [opts]
* @param {boolean} [opts.frontMatter=true] Switch feature to support YAML
* front-matter. If true, you can use Jekyll style directive setting to the
* first page.
*/
function parse(md, opts = {}) {
function _parse(md, opts = {}) {
const { marpit } = md

const applyBuiltinDirectives = (newProps, builtinDirectives) => {
Expand Down Expand Up @@ -213,4 +213,5 @@ function parse(md, opts = {}) {
})
}

export default marpitPlugin(parse)
export const parse = marpitPlugin(_parse)
export default parse
6 changes: 4 additions & 2 deletions src/markdown/directives/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function convertLoose(text, looseDirectives) {
/**
* Parse text as YAML by using js-yaml's FAILSAFE_SCHEMA.
*
* @alias module:markdown/directives/yaml
* @function yaml
* @param {String} text Target text.
* @param {boolean|string[]} [looseDirectives=false] By setting `true`, it try
* to parse as loose YAML only in defined Marpit built-in directives. You
Expand All @@ -63,7 +63,7 @@ function convertLoose(text, looseDirectives) {
* @returns {Object|false} Return parse result, or `false` when failed to parse.
*/

export default (text, looseDirectives = false) =>
export const yaml = (text, looseDirectives = false) =>
parse(
looseDirectives
? convertLoose(text, [
Expand All @@ -72,3 +72,5 @@ export default (text, looseDirectives = false) =>
])
: text
)

export default yaml
7 changes: 4 additions & 3 deletions src/markdown/fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const fragmentedListMarkups = ['*', ')']
/**
* Marpit fragment plugin.
*
* @alias module:markdown/fragment
* @function fragment
* @param {MarkdownIt} md markdown-it instance.
*/
function fragment(md) {
function _fragment(md) {
// Fragmented list
md.core.ruler.after('marpit_directives_parse', 'marpit_fragment', (state) => {
if (state.inlineMode) return
Expand Down Expand Up @@ -49,4 +49,5 @@ function fragment(md) {
})
}

export default marpitPlugin(fragment)
export const fragment = marpitPlugin(_fragment)
export default fragment
9 changes: 5 additions & 4 deletions src/markdown/header_and_footer.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/** @module */
import wrapTokens from '../helpers/wrap_tokens'
import { wrapTokens } from '../helpers/wrap_tokens'
import marpitPlugin from '../plugin'

/**
* Marpit header and footer plugin.
*
* At each slide, add header and footer that are provided by directives.
*
* @alias module:markdown/header_and_footer
* @function headerAndFooter
* @param {MarkdownIt} md markdown-it instance.
*/
function headerAndFooter(md) {
function _headerAndFooter(md) {
md.core.ruler.after(
'marpit_directives_apply',
'marpit_header_and_footer',
Expand Down Expand Up @@ -68,4 +68,5 @@ function headerAndFooter(md) {
)
}

export default marpitPlugin(headerAndFooter)
export const headerAndFooter = marpitPlugin(_headerAndFooter)
export default headerAndFooter
9 changes: 5 additions & 4 deletions src/markdown/heading_divider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @module */
import split from '../helpers/split'
import { split } from '../helpers/split'
import marpitPlugin from '../plugin'

/**
Expand All @@ -8,10 +8,10 @@ import marpitPlugin from '../plugin'
* Start a new slide page at before of headings by prepending hidden `<hr>`
* elements.
*
* @alias module:markdown/heading_divider
* @function headingDivider
* @param {MarkdownIt} md markdown-it instance.
*/
function headingDivider(md) {
function _headingDivider(md) {
const { marpit } = md

md.core.ruler.before('marpit_slide', 'marpit_heading_divider', (state) => {
Expand Down Expand Up @@ -56,4 +56,5 @@ function headingDivider(md) {
})
}

export default marpitPlugin(headingDivider)
export const headingDivider = marpitPlugin(_headingDivider)
export default headingDivider
7 changes: 4 additions & 3 deletions src/markdown/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import parse from './image/parse'
/**
* Marpit image plugin.
*
* @alias module:markdown/image
* @function image
* @param {MarkdownIt} md markdown-it instance.
*/
function image(md) {
function _image(md) {
parse(md)
apply(md)
}

export default marpitPlugin(image)
export const image = marpitPlugin(_image)
export default image
Loading

0 comments on commit c845961

Please sign in to comment.