ordered lists
parent
190441453b
commit
662a7d3f1a
12
README.md
12
README.md
|
@ -12,6 +12,7 @@ See https://www.dokuwiki.org/wiki:syntax
|
|||
* bold, italic, sub/sup, strikethrough
|
||||
* headings with equal sign
|
||||
* linebreaks (double backslash) are at this moment replaced with HTML BRs.
|
||||
* unordered lists (already native MD), ordered lists using dash to markdown
|
||||
|
||||
### embedding HTML
|
||||
|
||||
|
@ -36,14 +37,17 @@ Simply add custom.html and link to the website of your choice. Use Hugo's `{{ in
|
|||
|
||||
## TODO
|
||||
|
||||
### styling
|
||||
|
||||
* Figure out image links ala http://php.net|{{wiki:dokuwiki-128.png}}
|
||||
* Tables, should complex ones be supported or can I do a manual convert?
|
||||
* emoticons
|
||||
* no formatting (nowiki, %%) - should this just be a pre?
|
||||
|
||||
### structure
|
||||
|
||||
* build file structure - wire everything together
|
||||
* build header TOML with timestamps, draft false etc
|
||||
* ordered lists using dash to markdown?
|
||||
* emoticons
|
||||
* no formatting (nowiki) - should this just be a pre?
|
||||
* preventing of wiki markup %% - what to do with it?
|
||||
|
||||
## Not supported and probably will never be
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
import re
|
||||
|
||||
class MarkdownOrderedList:
|
||||
pattern = re.compile('(^-\s)(.*)', re.MULTILINE)
|
||||
|
||||
def convert(self, text):
|
||||
lines = text.split('\n')
|
||||
last_used_linenr = 0
|
||||
index = 0
|
||||
result = text
|
||||
|
||||
for match in MarkdownOrderedList.pattern.findall(text):
|
||||
line = ''.join(match)
|
||||
linenr = lines.index(line)
|
||||
|
||||
if last_used_linenr + 1 is linenr:
|
||||
index = index + 1
|
||||
else:
|
||||
index = 1
|
||||
last_used_linenr = linenr
|
||||
|
||||
result = result.replace(line, str(index) + '. ' + match[1])
|
||||
|
||||
return result
|
|
@ -0,0 +1,65 @@
|
|||
from unittest import TestCase
|
||||
|
||||
from src.markdown.lists import MarkdownOrderedList
|
||||
|
||||
|
||||
class TestMarkdownLists(TestCase):
|
||||
def setUp(self):
|
||||
self.converter = MarkdownOrderedList()
|
||||
|
||||
def test_dont_convert_if_no_list_found(self):
|
||||
self.assertEqual('hello there', self.converter.convert('hello there'))
|
||||
|
||||
def test_only_convert_dashes_if_beginning_sentence(self):
|
||||
src = '''
|
||||
- one-two-three
|
||||
- four
|
||||
|
||||
five - six
|
||||
'''
|
||||
expected = '''
|
||||
1. one-two-three
|
||||
2. four
|
||||
|
||||
five - six
|
||||
'''
|
||||
|
||||
self.assertEqual(expected, self.converter.convert(src))
|
||||
|
||||
def test_multiple_ordered_lists_in_text(self):
|
||||
src = '''
|
||||
- one
|
||||
- two
|
||||
|
||||
three
|
||||
- four
|
||||
- five
|
||||
six
|
||||
'''
|
||||
expected = '''
|
||||
1. one
|
||||
2. two
|
||||
|
||||
three
|
||||
1. four
|
||||
2. five
|
||||
six
|
||||
'''
|
||||
|
||||
self.assertEqual(expected, self.converter.convert(src))
|
||||
|
||||
def test_single_ordered_list(self):
|
||||
src = '''
|
||||
- one
|
||||
- two
|
||||
|
||||
three
|
||||
'''
|
||||
expected = '''
|
||||
1. one
|
||||
2. two
|
||||
|
||||
three
|
||||
'''
|
||||
|
||||
self.assertEqual(expected, self.converter.convert(src))
|
Loading…
Reference in New Issue