Created
August 2, 2019 00:01
-
-
Save DSchau/dc037e2f122c1048e5c67a5dcb72357c to your computer and use it in GitHub Desktop.
gatsby-remark-timestamps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* you will probably also want to do something like gatsby-remark-autolink-headers | |
* https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-remark-autolink-headers/src/gatsby-ssr.js | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const visit = require('unist-util-visit') | |
const TIMESTAMP_EXPR = /^\[(^\])+]/ | |
module.exports = function remarkPluginTranscripts({ markdownAST }) { | |
// node I'm not 100% sure of the structure of the node, it _may_ be children, but could be something else | |
visit(markdownAST, 'paragraph', node => { | |
const match = node.children.match(TIMESTAMP_EXPR) | |
if (!match) { | |
return | |
} | |
/* | |
* We now know we have a paragraph node that we can parse for a timestamp | |
* We'll want to transform the node to an HTML node like: | |
* <a href={`#playFrom=${timestamp}}>{timestamp}</a> | |
* <p>{contentWithoutTimestamp}</p> | |
*/ | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment