Skip to content

Instantly share code, notes, and snippets.

@jxe
Created April 10, 2018 15:52
Show Gist options
  • Save jxe/cebe1154c1ee2ff691332b3a3b3ba773 to your computer and use it in GitHub Desktop.
Save jxe/cebe1154c1ee2ff691332b3a3b3ba773 to your computer and use it in GitHub Desktop.
let text = `
# a taster of HSC 1
For 3-4 readers
This is a wild read that requires some intimacy with strangers. You'll be anonymous.
---- page ----
Let's start out with a game about our values.
---- form ----
Use this chart to fill in the blanks.
<Form>
</Form>
---- chat ----
Now share some of the words you came up with, others will guess which category they came from.
---- page ----
Let's see what else we can learn. Sometimes we are mixed up with values and norms.
`
function parse(text){
let [intro, ...sections] = text.split(/^----\s*/m)
let title = (intro.match(/^# (.*)$/m)||[])[1]
let readers = (intro.match(/for ([\d-]*) readers/i)||[])[1]
sections = sections.map(s => {
let [header, contents] = s.split(/\s*----\n/)
let [type, params] = header.split(/\s+/, 2)
return {type, params, contents}
})
return {intro, title, readers, sections}
}
console.log(parse(text))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment