Skip to content

Instantly share code, notes, and snippets.

@DSchau
Created August 2, 2019 00:01
Show Gist options
  • Save DSchau/dc037e2f122c1048e5c67a5dcb72357c to your computer and use it in GitHub Desktop.
Save DSchau/dc037e2f122c1048e5c67a5dcb72357c to your computer and use it in GitHub Desktop.
gatsby-remark-timestamps
/*
* 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
*/
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