emoji conversion, update README

This commit is contained in:
wgroeneveld 2017-01-15 17:33:15 +01:00
parent 8c40577459
commit 0e3f7aaa40
5 changed files with 70 additions and 6 deletions

View File

@ -29,11 +29,21 @@ See `test_hugo_file_config.py` for an example.
### general
Things that needed some conversion:
* code, file, inlinecode with single quotes
* bold, italic, sub/sup, strikethrough
* italic, 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
* ordered lists using dash to markdown
* emoji following this cheat sheet: http://www.webpagefx.com/tools/emoji-cheat-sheet/ - don't forget to enable emoji in your hugo config.
Things that are **the same** anyway:
* horizontal rule (4 slashes VS 3 or more)
* bold stuff using double asteriks
* unordered lists as asteriks
* sub/sup
### embedding HTML
@ -56,16 +66,22 @@ You'll have to come up with your own shortcodes for those.
See wp.html in the layouts directory. You could customize interwiki links from dokuwiki: `[[custom>somelink]]` would refer to some custom wiki.
Simply add custom.html and link to the website of your choice. Use Hugo's `{{ index .Params 0 }}` to get the link content.
### I want to create my own syntax conversion!
No problem, the project was made with extensibility in mind.
Simply drop a python script in the markdown submodule folder location and annotate it with the class decorator `@MarkdownConverter.Register`.
That way it's auto-loaded and wired in the main conversion.
## 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?
## Not supported and probably will never be
### Not supported and probably will never be
* embedding php - kill it with fire?
* macro's - kill it with fire?

32
src/markdown/emoji.py Normal file
View File

@ -0,0 +1,32 @@
from src.markdown_converter import MarkdownConverter
@MarkdownConverter.Register
class MarkdownEmoji():
# config as you like. http://www.webpagefx.com/tools/emoji-cheat-sheet/
config = {
'8-)': 'sunglasses',
'8-O': 'flushed',
':-(': 'worried',
':-)': 'simple_smile',
'=)': 'simple_smile',
':-/': 'confused',
':-\\': 'confused',
':-?': 'sweat',
':-D': 'laughing',
':-P': 'stuck_out_tongue',
':-O': 'open_mouth',
':-X': 'grimacing',
':-|': 'expressionless',
';-)': 'wink',
'^_^': 'smile',
':?:': 'question',
':!:': 'exclamation',
'LOL': 'laughing',
}
def convert(self, text):
result = text
for key, value in MarkdownEmoji.config.items():
result = result.replace(key, ':' + value + ':')
return result

View File

@ -2,7 +2,6 @@ from re import compile
from src.markdown_converter import MarkdownConverter
@MarkdownConverter.Register
class MarkdownHeader():
pattern = compile('(=+)(.*?)(=+)')

View File

@ -0,0 +1,17 @@
from unittest import TestCase
from src.markdown.emoji import MarkdownEmoji
class TestMarkdownEmoji(TestCase):
def setUp(self):
self.converter = MarkdownEmoji()
def test_replace_one_emoji(self):
self.assertEqual(":simple_smile:", self.converter.convert(":-)"))
def test_replace_some_emojis_in_one_line(self):
src = "hi! :-) how are you? :-/ heh"
expected = "hi! :simple_smile: how are you? :confused: heh"
self.assertEqual(expected, self.converter.convert(src))

View File

@ -10,7 +10,7 @@ class TestDokuWikiToHugo(TestCase):
def tearDown(self):
shutil.rmtree('output')
`
def test_convert_whole_dir(self):
DokuWikiToHugo().doku_to_hugo('subdir')
expected = Path("output/subdir/moar/dokuwiki_header_in_subdir.txt").read_text()