Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@snowyu
Last active December 12, 2018 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save snowyu/93f6fdc6ed79a44bd720e8856dc07046 to your computer and use it in GitHub Desktop.
Save snowyu/93f6fdc6ed79a44bd720e8856dc07046 to your computer and use it in GitHub Desktop.
The new style markdown KNI

I haven’t really thought about it yet. It is not perfect, just a start:

---
// the defaults front-matter config: YAML
type:
  gold: 
    type: integer
  arrow: integer
  hits: number
  health:
    type: integer
    min: 0
    max: 100
my:
   gold: 2
   arrow: 0
   health: 100
shop: 
  gold: 0
  arrow: 100
---

# <a name="main">A Wonder Adventure Story for You

You enter the fletcher’s shop. The fletcher beckons, “There are arrows for sale 
and a range out back you can try your skills and maybe win your fortune. For each 
hit, you win more gold!” 

## <a name="shop">A Mysterious Shop

You have `{pluralize(my.arrow, 'arrow')}` `{my.arrow ? 'and' : 'but' }` `{pluralize(my.gold, 'gold')}`.

+ `{--my.gold}` `{my.arrow += 3}`
    [You b[B]uy 3 arrows for a gold piece. ]
  + `{++my.gold}` `{my.arrow -= 4}`
    [You s[S]ell 4 arrows for a gold piece. ]
  + [You walk through the door to [Visit] the archery range. ]
    `[range]`
  + [Leave the store. ]
    You depart the store through the back door with `{pluralize(my.gold, 'gold')}`.
    `{my.hits?}`
    - All told you scored COUNT(HITS).
    `[END]`
  >

## <a name="range"> The Archery Range

You have `{pluralize(my.arrow, 'arrow')}`.

  + `{--my.arrow}`
    [You s[S]hoot an arrow[.]]
    - `{switch random(4)}`
      - `{case 1}`: and hit the target, winning `{my.hits? 'another' : 'a' }` gold piece!
        `{++my.hits}`
      - `{case 4}`: and miss.
    - `{my.arrow += 3}`
  + [You r[R]eturn to the archery shop. ]
    `[shop]`
  >

```ts
// the embed script supported.
import { pluralize as pluralizeWord } from 'pluralize';

function pluralize(value: number, word: string) {
  let result;
  if (value <= 0) {
   result = `none ${word}`;
  } else if (value > 1) {
   result = `${value}`
   result += pluralizeWord(word)
  } else {
   result = `${value} ${word}`
  }
  return result;
}


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment