transformContent.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import t from 'tap';
  2. import {testContentFunctions} from '#test-lib';
  3. testContentFunctions(t, 'transformContent (snapshot)', async (t, evaluate) => {
  4. await evaluate.load({
  5. mock: {
  6. image: evaluate.stubContentFunction('image'),
  7. },
  8. });
  9. const extraDependencies = {
  10. wikiData: {
  11. albumData: [
  12. {directory: 'cool-album', name: 'Cool Album', color: '#123456'},
  13. ],
  14. },
  15. to: (key, ...args) => `to-${key}/${args.join('/')}`,
  16. };
  17. const quickSnapshot = (message, content, slots) =>
  18. evaluate.snapshot(message, {
  19. name: 'transformContent',
  20. args: [content],
  21. extraDependencies,
  22. slots,
  23. });
  24. quickSnapshot(
  25. 'two text paragraphs',
  26. `Hello, world!\n` +
  27. `Wow, this is very cool.`);
  28. quickSnapshot(
  29. 'links to a thing',
  30. `This is [[album:cool-album|my favorite album]].\n` +
  31. `That's right, [[album:cool-album]]!`);
  32. quickSnapshot(
  33. 'indent on a directly following line',
  34. `<div>\n` +
  35. ` <span>Wow!</span>\n` +
  36. `</div>`);
  37. quickSnapshot(
  38. 'indent on an indierctly following line',
  39. `Some text.\n` +
  40. `Yes, some more text.\n` +
  41. `\n` +
  42. ` I am hax0rz!!\n` +
  43. ` All yor base r blong 2 us.\n` +
  44. `\n` +
  45. `Aye.\n` +
  46. `Aye aye aye.`);
  47. quickSnapshot(
  48. 'hanging indent list',
  49. `Hello!\n` +
  50. `\n` +
  51. `* I am a list item and I\n` +
  52. ` go on and on and on\n` +
  53. ` and on and on and on.\n` +
  54. `\n` +
  55. `* I am another list item.\n` +
  56. ` Yeah.\n` +
  57. `\n` +
  58. `In-between!\n` +
  59. `\n` +
  60. `* Spooky,\n` +
  61. ` spooky, I say!\n` +
  62. `* Following list item.\n` +
  63. ` No empty line around me.\n` +
  64. `* Very cool.\n` +
  65. ` So, so cool.\n` +
  66. `\n` +
  67. `Goodbye!`);
  68. quickSnapshot(
  69. 'inline images',
  70. `<img src="snooping.png"> as USUAL...\n` +
  71. `What do you know? <img src="cowabunga.png" width="24" height="32">\n` +
  72. `[[album:cool-album|I'm on the left.]]<img src="im-on-the-right.jpg">\n` +
  73. `<img src="im-on-the-left.jpg">[[album:cool-album|I'm on the right.]]\n` +
  74. `Media time! <img src="media/misc/interesting.png"> Oh yeah!\n` +
  75. `<img src="must.png"><img src="stick.png"><img src="together.png">\n` +
  76. `And... all done! <img src="end-of-source.png">`);
  77. quickSnapshot(
  78. 'non-inline image #1',
  79. `<img src="spark.png">`);
  80. quickSnapshot(
  81. 'non-inline image #2',
  82. `Rad.\n` +
  83. `<img src="spark.png">`);
  84. quickSnapshot(
  85. 'non-inline image #3',
  86. `<img src="spark.png">\n` +
  87. `Baller.`);
  88. quickSnapshot(
  89. 'dates',
  90. `[[date:2023-04-13]] Yep!\n` +
  91. `Very nice: [[date:25 October 2413]]`);
  92. quickSnapshot(
  93. 'super basic string',
  94. `Neat listing: [[string:listingPage.listAlbums.byDate.title]]`);
  95. quickSnapshot(
  96. 'basic markdown',
  97. `Hello *world!* This is **SO COOL.**`);
  98. quickSnapshot(
  99. 'escape entire tag',
  100. `\\[[album:cool-album|spooky]] [[album:cool-album|scary]]`);
  101. quickSnapshot(
  102. 'escape end of tag',
  103. `My favorite album is [[album:cool-album|[Tactical Omission\\]]].\n` +
  104. `Your favorite album is [[album:cool-album|[Tactical Wha-Huh-Now]]].`);
  105. quickSnapshot(
  106. 'escape markdown',
  107. `What will it be, *ye fool?* \\*arr*`);
  108. quickSnapshot(
  109. 'lyrics - basic line breaks',
  110. `Hey, ho\n` +
  111. `And away we go\n` +
  112. `Truly, music\n` +
  113. `\n` +
  114. `(Oh yeah)\n` +
  115. `(That's right)`,
  116. {mode: 'lyrics'});
  117. quickSnapshot(
  118. 'lyrics - repeated and edge line breaks',
  119. `\n\nWell, you know\nHow it goes\n\n\nYessiree\n\n\n`,
  120. {mode: 'lyrics'});
  121. quickSnapshot(
  122. 'lyrics - line breaks around tags',
  123. `The date be [[date:13 April 2004]]\n` +
  124. `I say, the date be [[date:13 April 2004]]\n` +
  125. `[[date:13 April 2004]]\n` +
  126. `[[date:13 April 2004]][[date:13 April 2004]][[date:13 April 2004]]\n` +
  127. `(Aye!)\n` +
  128. `\n` +
  129. `[[date:13 April 2004]]\n` +
  130. `[[date:13 April 2004]][[date:13 April 2004]]\n` +
  131. `[[date:13 April 2004]]\n` +
  132. `\n` +
  133. `[[date:13 April 2004]]\n` +
  134. `[[date:13 April 2004]], and don't ye forget it`,
  135. {mode: 'lyrics'});
  136. // TODO: Snapshots for mode: inline
  137. // TODO: Snapshots for mode: single-link
  138. });