Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. module.exports = toMarkdown
  2. var zwitch = require('zwitch')
  3. var configure = require('./configure')
  4. var defaultHandlers = require('./handle')
  5. var defaultJoin = require('./join')
  6. var defaultUnsafe = require('./unsafe')
  7. function toMarkdown(tree, options) {
  8. var settings = options || {}
  9. var context = {
  10. enter: enter,
  11. stack: [],
  12. unsafe: [],
  13. join: [],
  14. handlers: {},
  15. options: {}
  16. }
  17. var result
  18. configure(context, {
  19. unsafe: defaultUnsafe,
  20. join: defaultJoin,
  21. handlers: defaultHandlers
  22. })
  23. configure(context, settings)
  24. if (context.options.tightDefinitions) {
  25. context.join = [joinDefinition].concat(context.join)
  26. }
  27. context.handle = zwitch('type', {
  28. invalid: invalid,
  29. unknown: unknown,
  30. handlers: context.handlers
  31. })
  32. result = context.handle(tree, null, context, {before: '\n', after: '\n'})
  33. if (
  34. result &&
  35. result.charCodeAt(result.length - 1) !== 10 &&
  36. result.charCodeAt(result.length - 1) !== 13
  37. ) {
  38. result += '\n'
  39. }
  40. return result
  41. function enter(name) {
  42. context.stack.push(name)
  43. return exit
  44. function exit() {
  45. context.stack.pop()
  46. }
  47. }
  48. }
  49. function invalid(value) {
  50. throw new Error('Cannot handle value `' + value + '`, expected node')
  51. }
  52. function unknown(node) {
  53. throw new Error('Cannot handle unknown node `' + node.type + '`')
  54. }
  55. function joinDefinition(left, right) {
  56. // No blank line between adjacent definitions.
  57. if (left.type === 'definition' && left.type === right.type) {
  58. return 0
  59. }
  60. }