aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBlake DeMarcy <ofunknowndescent@gmail.com>2017-04-24 15:42:37 -0500
committerBlake DeMarcy <ofunknowndescent@gmail.com>2017-04-24 15:42:37 -0500
commit10a65c2d7c507c77495f9d99d59436065e17f5a9 (patch)
tree90a2c685a93c57361dd69b5e8f03f12472048931
parent7e1996ec0548665c78c023ebd409421561a91b18 (diff)
downloadbbj-10a65c2d7c507c77495f9d99d59436065e17f5a9.tar.gz
more reliable and escapable formatting; add [dim]
-rw-r--r--clients/urwid/main.py34
-rw-r--r--src/formatting.py38
2 files changed, 40 insertions, 32 deletions
diff --git a/clients/urwid/main.py b/clients/urwid/main.py
index 9a43e43..4b0e934 100644
--- a/clients/urwid/main.py
+++ b/clients/urwid/main.py
@@ -83,24 +83,27 @@ format_help = [
"[red: Whitespace]",
+ "Single line breaks in the body join into eachother to form sentences, "
+ "putting a space where the break was. This works like html. When you want "
+ "to split it off into a paragraph, **use two or more line breaks.**",
+
"When you're composing, it is desirable to introduce linebreaks into the "
"body to keep it from overflowing the screen. However, you __dont__ want "
"that same spacing to bleed over to other people's screens, because clients "
- "will wrap the text themselves.",
+ "will wrap the text themselves according to user preferences or implementation "
+ "details. Thats why it works like this.",
- "Single line breaks in the body join into eachother to form sentences, "
- "putting a space where the break was. This works like html. When you want "
- "to split it off into a paragraph, **use two line breaks.**",
"[red: Colors, Bold, Underline & Expressions]",
"You can use [rainbow: rainbow], [red: red], [yellow: yellow], [green: green], "
"[blue: blue], [cyan: cyan], [magenta: and magenta], **bold**, and __underline__ "
- "inside of your posts. **bold\nworks like this**, __and\nunderlines like this__. "
- "The symbolic, markdown form of these directives does NOT allow escaping, and "
- "can only apply to up to 20 characters on the same line. They are best used on short "
- "phrases. However, you can use a different syntax for it, which is also required to use "
- "colors: these expressions \[bold: look like this] and are much more reliable. "
+ "inside of your posts. \**bold works like this\**, \__and underlines like this\__. "
+ "You can escape these expressions \\\**like this\\\**. They can span up to the full width "
+ "of the same line. They are best used on shorter phrases. "
+ "However, you can use a different syntax for it, which is also required to use "
+ "colors: these expressions \[bold: look like this] and have less restrictions.",
+
"The colon and the space following it are important. When you use these "
"expressions, the __first__ space is not part of the content, but any characters, "
"including spaces, that follow it are included in the body. The formatting will "
@@ -116,8 +119,8 @@ format_help = [
"The following directives may be used in this form: red, yellow, green, blue, cyan, "
"magenta, bold, underline, and rainbow. Nesting expressions into eachother will "
- "override the parent directives until it closes. Thus, nesting is valid but doesn't produce "
- "layered results.",
+ "override the parent directives until the innermost expression closes. Thus, nesting "
+ "is valid but doesn't produce layered results on the command line client.",
"[red: Quotes & Greentext]",
@@ -126,7 +129,9 @@ format_help = [
"this violates the sentence structure outlined in the **Whitespace** section above, "
"so you may introduce >greentext without splicing into seperate paragraphs. The '>' "
"must be the first character on the line with no whitespace before it.\n>it looks like this\n"
- "and the paragraph doesnt have to break on either side.",
+ "and the paragraph doesnt have to break on either side. The formatter is smart enough to "
+ "differentiate between >>greentext with multiple arrows and numeric quotes (outlined below) "
+ "given that the text doesn't start with any numbers.",
"When using numeric quotes, they are highlighted and the author's name will show "
"next to them in the thread. You can press enter when focused on a message to view "
@@ -949,7 +954,7 @@ class App(object):
widget, app.loop.widget,
align=("relative", 50),
valign=("relative", 50),
- width=("relative", 98),
+ width=app.prefs["max_text_width"],
height=("relative", 60)
)
@@ -1338,6 +1343,9 @@ class MessageBody(urwid.Text):
color = str(colornames.index(directive))
result.append((color, body))
+ elif directive == "dim":
+ result.append((directive, body))
+
elif directive in ["underline", "bold"]:
result.append((directive, body))
diff --git a/src/formatting.py b/src/formatting.py
index c00b0ec..a3eb73d 100644
--- a/src/formatting.py
+++ b/src/formatting.py
@@ -65,25 +65,28 @@ they are only removed when they occur before a valid expression.
import re
colors = [
-#0, 1 2 3 4 5 6
- "red", "yellow", "green", "blue", "cyan", "magenta"
+#0, 1 2 3 4 5 6 dim is not used in color api
+ "red", "yellow", "green", "blue", "cyan", "magenta", "dim"
]
markup = [
"bold", "underline", "linequote", "quote", "rainbow"
]
-# PS: regex parsing is no longer used for these, preserving anyways
-# tokens being [red: this will be red] and [bold: this will be bold]
-# tokens = re.compile(r"\[(%s): (.+?)]" % "|".join(colors + markup), flags=re.DOTALL)
-# linequotes being chan-style greentext,
-# >like this
-# linequotes = re.compile("^(>.+)$", flags=re.MULTILINE)
# quotes being references to other post_ids, like >>34 or >>0 for OP
quotes = re.compile(">>([0-9]+)")
-bold = re.compile(r"\*{2}(.{1,20})\*{2}")
-underline = re.compile(r"__(.{1,20})__")
+bold = re.compile(r"(?<!\\)\*{2}(.+?)(?<!\\)\*{2}")
+underline = re.compile(r"(?<!\\)_{2}(.+?)(?<!\\)_{2}")
+escapes = re.compile(r"\\([*_]{2})")
+
+
+def apply_directives(text):
+ # is there a better way to do this? smh....
+ text = quotes.sub(lambda m: "[quote: %s]" % m.group(1), text)
+ text = bold.sub(lambda m: "[bold: %s]" % m.group(1), text)
+ text = underline.sub(lambda m: "[underline: %s]" % m.group(1), text)
+ return escapes.sub(lambda m: m.group(1), text)
def parse_segments(text, sanitize_linequotes=True):
@@ -99,19 +102,16 @@ def parse_segments(text, sanitize_linequotes=True):
for segment in [s.strip() for s in paragraph.split("\n")]:
if not segment:
continue
- segment = quotes.sub(lambda m: "[quote: %s]" % m.group(1), segment)
- segment = bold.sub(lambda m: "[bold: %s]" % m.group(1), segment)
- segment = underline.sub(lambda m: "[underline: %s]" % m.group(1), segment)
- if segment.startswith(">"):
+ _fp = segment.find(" ")
+ first_word = segment[:_fp] if _fp != -1 else segment
+ if segment.startswith(">") and not quotes.search(first_word):
if sanitize_linequotes:
inner = segment.replace("]", "\\]")
else:
- inner = segment
- segment = "[linequote: %s]" % inner
- # pg = pg[0:-1]
- pg += segment
+ inner = apply_directives(segment)
+ pg += "[linequote: %s]" % inner
else:
- pg += segment + " "
+ pg += apply_directives(segment) + " "
result.append(pg.strip())
return result
Un proyecto texto-plano.xyz