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.

code.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. module.exports = code
  2. var repeat = require('repeat-string')
  3. var streak = require('longest-streak')
  4. var formatCodeAsIndented = require('../util/format-code-as-indented')
  5. var checkFence = require('../util/check-fence')
  6. var indentLines = require('../util/indent-lines')
  7. var safe = require('../util/safe')
  8. function code(node, _, context) {
  9. var marker = checkFence(context)
  10. var raw = node.value || ''
  11. var suffix = marker === '`' ? 'GraveAccent' : 'Tilde'
  12. var value
  13. var sequence
  14. var exit
  15. var subexit
  16. if (formatCodeAsIndented(node, context)) {
  17. exit = context.enter('codeIndented')
  18. value = indentLines(raw, map)
  19. } else {
  20. sequence = repeat(marker, Math.max(streak(raw, marker) + 1, 3))
  21. exit = context.enter('codeFenced')
  22. value = sequence
  23. if (node.lang) {
  24. subexit = context.enter('codeFencedLang' + suffix)
  25. value += safe(context, node.lang, {
  26. before: '`',
  27. after: ' ',
  28. encode: ['`']
  29. })
  30. subexit()
  31. }
  32. if (node.lang && node.meta) {
  33. subexit = context.enter('codeFencedMeta' + suffix)
  34. value +=
  35. ' ' +
  36. safe(context, node.meta, {
  37. before: ' ',
  38. after: '\n',
  39. encode: ['`']
  40. })
  41. subexit()
  42. }
  43. value += '\n'
  44. if (raw) {
  45. value += raw + '\n'
  46. }
  47. value += sequence
  48. }
  49. exit()
  50. return value
  51. }
  52. function map(line, _, blank) {
  53. return (blank ? '' : ' ') + line
  54. }