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.

inline-code.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. module.exports = inlineCode
  2. inlineCode.peek = inlineCodePeek
  3. var patternCompile = require('../util/pattern-compile')
  4. function inlineCode(node, parent, context) {
  5. var value = node.value || ''
  6. var sequence = '`'
  7. var index = -1
  8. var pattern
  9. var expression
  10. var match
  11. var position
  12. // If there is a single grave accent on its own in the code, use a fence of
  13. // two.
  14. // If there are two in a row, use one.
  15. while (new RegExp('(^|[^`])' + sequence + '([^`]|$)').test(value)) {
  16. sequence += '`'
  17. }
  18. // If this is not just spaces or eols (tabs don’t count), and either the
  19. // first or last character are a space, eol, or tick, then pad with spaces.
  20. if (
  21. /[^ \r\n]/.test(value) &&
  22. (/[ \r\n`]/.test(value.charAt(0)) ||
  23. /[ \r\n`]/.test(value.charAt(value.length - 1)))
  24. ) {
  25. value = ' ' + value + ' '
  26. }
  27. // We have a potential problem: certain characters after eols could result in
  28. // blocks being seen.
  29. // For example, if someone injected the string `'\n# b'`, then that would
  30. // result in an ATX heading.
  31. // We can’t escape characters in `inlineCode`, but because eols are
  32. // transformed to spaces when going from markdown to HTML anyway, we can swap
  33. // them out.
  34. while (++index < context.unsafe.length) {
  35. pattern = context.unsafe[index]
  36. // Only look for `atBreak`s.
  37. // Btw: note that `atBreak` patterns will always start the regex at LF or
  38. // CR.
  39. if (!pattern.atBreak) continue
  40. expression = patternCompile(pattern)
  41. while ((match = expression.exec(value))) {
  42. position = match.index
  43. // Support CRLF (patterns only look for one of the characters).
  44. if (
  45. value.charCodeAt(position) === 10 /* `\n` */ &&
  46. value.charCodeAt(position - 1) === 13 /* `\r` */
  47. ) {
  48. position--
  49. }
  50. value = value.slice(0, position) + ' ' + value.slice(match.index + 1)
  51. }
  52. }
  53. return sequence + value + sequence
  54. }
  55. function inlineCodePeek() {
  56. return '`'
  57. }