Add code snippets to long-form stories.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import unittest
|
||||
|
||||
import app as application
|
||||
|
||||
|
||||
class CodeSnippetTestCase(unittest.TestCase):
|
||||
def test_fenced_code_is_parsed_with_its_language(self):
|
||||
blocks = application.article_blocks('Intro\n```python\nprint("hi")\n```\nEnd', [])
|
||||
|
||||
self.assertEqual(blocks[0], ("text", "Intro\n"))
|
||||
self.assertEqual(blocks[1], ("code", {"language": "python", "content": 'print("hi")'}))
|
||||
self.assertEqual(blocks[2], ("text", "\nEnd"))
|
||||
|
||||
def test_code_fence_keeps_image_marker_as_literal_code(self):
|
||||
image = {"filename": "step.webp"}
|
||||
blocks = application.article_blocks("```\n[[image:1]]\n```\n[[image:1]]", [image])
|
||||
|
||||
self.assertEqual(blocks[0], ("code", {"language": "text", "content": "[[image:1]]"}))
|
||||
self.assertEqual(blocks[1], ("text", "\n"))
|
||||
self.assertEqual(blocks[2], ("image", image))
|
||||
|
||||
def test_unterminated_fence_is_plain_text(self):
|
||||
body = "```python\nprint('not closed')"
|
||||
|
||||
self.assertEqual(application.article_blocks(body, []), [("text", body)])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user