Compare commits
1 Commits
66ccb66211
...
9b319a90dc
Author | SHA1 | Date | |
---|---|---|---|
|
9b319a90dc |
@ -113,7 +113,7 @@ BEGIN_BLOCK_RE = re.compile(r"^\s*#\+BEGIN_(?P<subtype>[^ ]+)(?P<arguments>.*)$"
|
||||
END_BLOCK_RE = re.compile(r"^\s*#\+END_(?P<subtype>[^ ]+)\s*$", re.I)
|
||||
RESULTS_DRAWER_RE = re.compile(r"^\s*:results:\s*$", re.I)
|
||||
CodeSnippet = collections.namedtuple(
|
||||
"CodeSnippet", ("name", "content", "result", "language", "arguments")
|
||||
"CodeSnippet", ("name", "content", "result", "arguments")
|
||||
)
|
||||
|
||||
# Groupings
|
||||
@ -916,23 +916,14 @@ class Headline:
|
||||
# the content parsing must be re-thinked
|
||||
contents = contents[:-1]
|
||||
|
||||
language = None
|
||||
if arguments is not None:
|
||||
arguments = arguments.strip()
|
||||
if " " in arguments:
|
||||
language = arguments[: arguments.index(" ")]
|
||||
arguments = arguments[arguments.index(" ") + 1 :]
|
||||
sections.append(
|
||||
{
|
||||
"line_first": start + 1,
|
||||
"line_last": end - 1,
|
||||
"content": contents,
|
||||
"arguments": arguments,
|
||||
"language": language,
|
||||
"name": name,
|
||||
}
|
||||
)
|
||||
name = None
|
||||
arguments = None
|
||||
line_start = None
|
||||
|
||||
@ -984,14 +975,9 @@ class Headline:
|
||||
content = section["content"]
|
||||
code_result = section.get("result", None)
|
||||
arguments = section.get("arguments", None)
|
||||
name = section.get("name", None)
|
||||
results.append(
|
||||
CodeSnippet(
|
||||
content=content,
|
||||
result=code_result,
|
||||
arguments=arguments,
|
||||
language=language,
|
||||
name=name,
|
||||
name=name, content=content, result=code_result, arguments=arguments
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -481,7 +481,6 @@ class TestSerde(unittest.TestCase):
|
||||
snippets = list(doc.get_code_snippets())
|
||||
self.assertEqual(len(snippets), 3)
|
||||
self.assertEqual(snippets[0].name, "first-code-name")
|
||||
self.assertEqual(snippets[0].language, "shell")
|
||||
self.assertEqual(
|
||||
snippets[0].content,
|
||||
'echo "This is a test"\n'
|
||||
@ -489,7 +488,7 @@ class TestSerde(unittest.TestCase):
|
||||
+ "exit 0 # Exit successfully",
|
||||
)
|
||||
self.assertEqual(
|
||||
snippets[0].arguments.split(), [":results", "verbatim"]
|
||||
snippets[0].arguments.split(), ["shell", ":results", "verbatim"]
|
||||
)
|
||||
self.assertEqual(
|
||||
snippets[0].result,
|
||||
@ -497,7 +496,6 @@ class TestSerde(unittest.TestCase):
|
||||
)
|
||||
|
||||
self.assertEqual(snippets[1].name, None)
|
||||
self.assertEqual(snippets[1].language, "shell")
|
||||
self.assertEqual(
|
||||
snippets[1].content,
|
||||
'echo "This is another test"\n'
|
||||
@ -509,7 +507,6 @@ class TestSerde(unittest.TestCase):
|
||||
)
|
||||
|
||||
self.assertEqual(snippets[2].name, None)
|
||||
self.assertEqual(snippets[2].language, "c")
|
||||
self.assertEqual(
|
||||
snippets[2].content,
|
||||
"/* This code has to be escaped to\n"
|
||||
|
Loading…
Reference in New Issue
Block a user