Skip to content

Commit

Permalink
Merge pull request #221 from michaelnt/headings_with_text
Browse files Browse the repository at this point in the history
Attributes are now added to the first line of a heading item
  • Loading branch information
jacebrowning committed Feb 12, 2017
2 parents 3e9776c + 4eb0c10 commit c3c8a7d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
6 changes: 3 additions & 3 deletions doorstop/core/publisher.py
Expand Up @@ -282,15 +282,15 @@ def _lines_markdown(obj, linkify=False):
level = _format_level(item.level)

if item.heading:

text_lines = item.text.splitlines()
# Level and Text
if settings.PUBLISH_HEADING_LEVELS:
standard = "{h} {l} {t}".format(h=heading, l=level, t=item.text)
standard = "{h} {l} {t}".format(h=heading, l=level, t=text_lines[0])
else:
standard = "{h} {t}".format(h=heading, t=item.text)
attr_list = _format_md_attr_list(item, linkify)
yield standard + attr_list

yield from text_lines[1:]
else:

# Level and UID
Expand Down
25 changes: 24 additions & 1 deletion doorstop/core/test/test_publisher.py
Expand Up @@ -8,7 +8,7 @@
from doorstop.common import DoorstopError
from doorstop.core import publisher

from doorstop.core.test import FILES, EMPTY, MockDataMixIn
from doorstop.core.test import FILES, EMPTY, MockDataMixIn, MockItemAndVCS


class TestModule(MockDataMixIn, unittest.TestCase):
Expand Down Expand Up @@ -162,6 +162,29 @@ def test_lines_text_item_heading_no_heading_levels(self):
# Assert
self.assertEqual(expected, text)

def test_single_line_heading_to_markdown(self):
"""A single line heading is published as a heading with an attribute equal to the item id"""
expected = "## 1.1 Heading {#req3 }\n\n"
lines = publisher.publish_lines(self.item, '.md', linkify=True)
# Act
text = ''.join(line + '\n' for line in lines)
# Assert
self.assertEqual(expected, text)

def test_multi_line_heading_to_markdown(self):
"""A multi line heading is published as a heading with an attribute equal to the item id"""
item = MockItemAndVCS('path/to/req3.yml',
_file=("links: [sys3]" + '\n'
"text: 'Heading\n\nThis section describes publishing.'" + '\n'
"level: 1.1.0" + '\n'
"normative: false"))
expected = "## 1.1 Heading {#req3 }\nThis section describes publishing.\n\n"
lines = publisher.publish_lines(item, '.md', linkify=True)
# Act
text = ''.join(line + '\n' for line in lines)
# Assert
self.assertEqual(expected, text)

@patch('doorstop.settings.PUBLISH_CHILD_LINKS', False)
def test_lines_text_item_normative(self):
"""Verify text can be published from an item (normative)."""
Expand Down

0 comments on commit c3c8a7d

Please sign in to comment.