Skip to content

Commit

Permalink
Use - and + for file link prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
loganharbour committed Nov 5, 2024
1 parent e7653ff commit d770446
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions python/MooseDocs/extensions/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def createToken(self, parent, info, page, settings):
class FileListingCommand(LocalListingCommand):
COMMAND = 'listing'
SUBCOMMAND = '*'
DEFAULT_BEFORE_LINK_PREFIX = 'Before'
DEFAULT_AFTER_LINK_PREFIX = 'After'
DEFAULT_BEFORE_LINK_PREFIX = '-'
DEFAULT_AFTER_LINK_PREFIX = '+'

@staticmethod
def defaultSettings():
Expand Down Expand Up @@ -151,9 +151,9 @@ def get_content(filename):
if settings['link']:
if settings['diff']:
modal.ModalSourceLink(flt, src=before_filename, language=link_lang,
link_prefix=settings['before_link_prefix'] + ':')
link_prefix=settings['before_link_prefix'])
html.Tag(flt, 'link_break', string='<br>')
link_prefix = (settings['after_link_prefix'] + ':') if settings['diff'] else None
link_prefix = (settings['after_link_prefix']) if settings['diff'] else None
modal.ModalSourceLink(flt, src=filename, language=link_lang,
link_prefix=link_prefix)

Expand Down
28 changes: 14 additions & 14 deletions python/MooseDocs/test/extensions/test_listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ class TestFileListingDiff(MooseDocsTestCase):
DIFF = listing.FileListingCommand.codeDiff(CODE, BEFORE_CODE)
TEXT = f'!listing {FILE} diff={DIFF_FILE}'

BEFORE_PREFIX = 'Foo'
AFTER_PREFIX = 'Bar'
BEFORE_PREFIX = 'Foo:'
AFTER_PREFIX = 'Bar:'
PREFIXED_TEST = f'{TEXT} before_link_prefix={BEFORE_PREFIX} after_link_prefix={AFTER_PREFIX}'

def testAST(self):
Expand All @@ -456,15 +456,15 @@ def testAST(self):
self.assertToken(ast(0), 'Code', content=self.DIFF, style=CODE_STYLE,
language='diff-cpp diff-highlight')
self.assertToken(ast(1), 'ModalSourceLink', size=0)
self.assertEqual(ast(1)['link_prefix'], 'Before:')
self.assertEqual(ast(1)['link_prefix'], '-')
self.assertToken(ast(2), 'link_break')
self.assertToken(ast(3), 'ModalSourceLink', size=0)
self.assertEqual(ast(3)['link_prefix'], 'After:')
self.assertEqual(ast(3)['link_prefix'], '+')

ast = self.tokenize(self.PREFIXED_TEST)
self.assertSize(ast, 4)
self.assertEqual(ast(1)['link_prefix'], f'{self.BEFORE_PREFIX}:')
self.assertEqual(ast(3)['link_prefix'], f'{self.AFTER_PREFIX}:')
self.assertEqual(ast(1)['link_prefix'], f'{self.BEFORE_PREFIX}')
self.assertEqual(ast(3)['link_prefix'], f'{self.AFTER_PREFIX}')

def testHTML(self):
_, res = self.execute(self.TEXT)
Expand All @@ -474,16 +474,16 @@ def testHTML(self):
self.assertHTMLString(res(0,0)(0), content=self.DIFF)
self.assertHTMLTag(res(1), 'span', size=1, class_='moose-source-filename')
self.assertHTMLString(res(1,0),
content=f'({listing.FileListingCommand.DEFAULT_BEFORE_LINK_PREFIX}: {self.DIFF_FILE})')
content=f'({listing.FileListingCommand.DEFAULT_BEFORE_LINK_PREFIX} {self.DIFF_FILE})')
self.assertHTMLString(res(2), '<br>')
self.assertHTMLTag(res(3), 'span', size=1, class_='moose-source-filename')
self.assertHTMLString(res(3,0),
content=f'({listing.FileListingCommand.DEFAULT_AFTER_LINK_PREFIX}: {self.FILE})')
content=f'({listing.FileListingCommand.DEFAULT_AFTER_LINK_PREFIX} {self.FILE})')

_, res = self.execute(self.PREFIXED_TEST)
self.assertHTMLTag(res, 'body', size=4)
self.assertHTMLString(res(1,0), content=f'({self.BEFORE_PREFIX}: {self.DIFF_FILE})')
self.assertHTMLString(res(3,0), content=f'({self.AFTER_PREFIX}: {self.FILE})')
self.assertHTMLString(res(1,0), content=f'({self.BEFORE_PREFIX} {self.DIFF_FILE})')
self.assertHTMLString(res(3,0), content=f'({self.AFTER_PREFIX} {self.FILE})')

def testMaterialize(self):
_, res = self.execute(self.TEXT, renderer=base.MaterializeRenderer())
Expand All @@ -493,18 +493,18 @@ def testMaterialize(self):
self.assertHTMLString(res(0,0)(0), content=self.DIFF)
self.assertHTMLTag(res(1), 'a', size=1, class_='moose-source-filename tooltipped modal-trigger')
self.assertHTMLString(res(1,0),
content=f'({listing.FileListingCommand.DEFAULT_BEFORE_LINK_PREFIX}: {self.DIFF_FILE})')
content=f'({listing.FileListingCommand.DEFAULT_BEFORE_LINK_PREFIX} {self.DIFF_FILE})')
self.assertHTMLString(res(2), '<br>')
self.assertHTMLTag(res(3), 'a', size=1, class_='moose-source-filename tooltipped modal-trigger')
self.assertHTMLString(res(3,0),
content=f'({listing.FileListingCommand.DEFAULT_AFTER_LINK_PREFIX}: {self.FILE})')
content=f'({listing.FileListingCommand.DEFAULT_AFTER_LINK_PREFIX} {self.FILE})')
self.assertHTMLTag(res(4), 'div', class_='moose-modal modal')
self.assertHTMLTag(res(5), 'div', class_='moose-modal modal')

_, res = self.execute(self.PREFIXED_TEST, renderer=base.MaterializeRenderer())
self.assertHTMLTag(res, 'div', size=6, class_='moose-content')
self.assertHTMLString(res(1,0), content=f'({self.BEFORE_PREFIX}: {self.DIFF_FILE})')
self.assertHTMLString(res(3,0), content=f'({self.AFTER_PREFIX}: {self.FILE})')
self.assertHTMLString(res(1,0), content=f'({self.BEFORE_PREFIX} {self.DIFF_FILE})')
self.assertHTMLString(res(3,0), content=f'({self.AFTER_PREFIX} {self.FILE})')

def testCodeDiff(self):
CODE_split = self.CODE.splitlines()
Expand Down

0 comments on commit d770446

Please sign in to comment.