Commit 106dca60cdfe2bcffc9244743f91d9edd3762074
Improve logic (again) for stripping the post title out of the body
If the first line is short enough to be the title, and the second line is whitespace-only, then strip the first 2 lines from the body. Otherwise, the body is always the entire text. This should prevent splitting a paragraph, quote, list or similar block. This still doesn't handle a markdown list of paragraphs, where each item is separated by a blank line. It also doesn't handle Setext-style headings (underlined with '====' or '----').Greg K Nicholson committed on 10/17/2017, 7:55:20 AM
Parent: 21a0511ed1ef6bd7abc7a39ed23f49baa482377b
Files changed
scuttleblog.py | changed |
scuttleblog.py | |||
---|---|---|---|
@@ -69,13 +69,13 @@ | |||
69 | 69 … | ellipsis = '...' | |
70 | 70 … | if len(title) > maxlength: | |
71 | 71 … | title = title[:maxlength].rsplit(' ', 1)[0] + ellipsis | |
72 | 72 … | body = text | |
73 … | + elif len(text.splitlines()) > 2 \ | ||
74 … | + and re.fullmatch('^\s+$', str(text.splitlines[1])): | ||
75 … | + body = ''.join(text.splitlines(keepends=True)[2:]).strip() | ||
73 | 76 … | else: | |
74 | - if len(text.splitlines()) > 1: | ||
75 | - body = ''.join(text.splitlines(keepends=True)[1:]).strip() | ||
76 | - else: | ||
77 | - body = '' | ||
77 … | + body = text | ||
78 | 78 … | return {'title': title, 'body': body} | |
79 | 79 … | ||
80 | 80 … | def build_post_structure(p): | |
81 | 81 … | post = {} |
Built with git-ssb-web