more reliable and escapable formatting; add [dim]
This commit is contained in:
		
							parent
							
								
									7e1996ec05
								
							
						
					
					
						commit
						10a65c2d7c
					
				| @ -83,24 +83,27 @@ format_help = [ | |||||||
| 
 | 
 | ||||||
|     "[red: Whitespace]", |     "[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 " |     "When you're composing, it is desirable to introduce linebreaks into the " | ||||||
|     "body to keep it from overflowing the screen. However, you __dont__ want " |     "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 " |     "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]", |     "[red: Colors, Bold, Underline & Expressions]", | ||||||
| 
 | 
 | ||||||
|     "You can use [rainbow: rainbow], [red: red], [yellow: yellow], [green: green], " |     "You can use [rainbow: rainbow], [red: red], [yellow: yellow], [green: green], " | ||||||
|     "[blue: blue], [cyan: cyan], [magenta: and magenta], **bold**, and __underline__ " |     "[blue: blue], [cyan: cyan], [magenta: and magenta], **bold**, and __underline__ " | ||||||
|     "inside of your posts. **bold\nworks like this**, __and\nunderlines like this__. " |     "inside of your posts. \**bold works like this\**, \__and underlines like this\__. " | ||||||
|     "The symbolic, markdown form of these directives does NOT allow escaping, and " |     "You can escape these expressions \\\**like this\\\**. They can span up to the full width " | ||||||
|     "can only apply to up to 20 characters on the same line. They are best used on short " |     "of the same line. They are best used on shorter phrases. " | ||||||
|     "phrases. However, you can use a different syntax for it, which is also required to use " |     "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. " |     "colors: these expressions \[bold: look like this] and have less restrictions.", | ||||||
|  | 
 | ||||||
|     "The colon and the space following it are important. When you use these " |     "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, " |     "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 " |     "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, " |     "The following directives may be used in this form: red, yellow, green, blue, cyan, " | ||||||
|     "magenta, bold, underline, and rainbow. Nesting expressions into eachother will " |     "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 " |     "override the parent directives until the innermost expression closes. Thus, nesting " | ||||||
|     "layered results.", |     "is valid but doesn't produce layered results on the command line client.", | ||||||
| 
 | 
 | ||||||
|     "[red: Quotes & Greentext]", |     "[red: Quotes & Greentext]", | ||||||
| 
 | 
 | ||||||
| @ -126,7 +129,9 @@ format_help = [ | |||||||
|     "this violates the sentence structure outlined in the **Whitespace** section above, " |     "this violates the sentence structure outlined in the **Whitespace** section above, " | ||||||
|     "so you may introduce >greentext without splicing into seperate paragraphs. The '>' " |     "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" |     "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 " |     "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 " |     "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, |             widget, app.loop.widget, | ||||||
|             align=("relative", 50), |             align=("relative", 50), | ||||||
|             valign=("relative", 50), |             valign=("relative", 50), | ||||||
|             width=("relative", 98), |             width=app.prefs["max_text_width"], | ||||||
|             height=("relative", 60) |             height=("relative", 60) | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
| @ -1338,6 +1343,9 @@ class MessageBody(urwid.Text): | |||||||
|                     color = str(colornames.index(directive)) |                     color = str(colornames.index(directive)) | ||||||
|                     result.append((color, body)) |                     result.append((color, body)) | ||||||
| 
 | 
 | ||||||
|  |                 elif directive == "dim": | ||||||
|  |                     result.append((directive, body)) | ||||||
|  | 
 | ||||||
|                 elif directive in ["underline", "bold"]: |                 elif directive in ["underline", "bold"]: | ||||||
|                     result.append((directive, body)) |                     result.append((directive, body)) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -65,25 +65,28 @@ they are only removed when they occur before a valid expression. | |||||||
| import re | import re | ||||||
| 
 | 
 | ||||||
| colors = [ | colors = [ | ||||||
| #0,   1        2        3        4       5        6 | #0,   1        2        3        4       5        6       dim is not used in color api | ||||||
|     "red", "yellow", "green", "blue", "cyan", "magenta" |     "red", "yellow", "green", "blue", "cyan", "magenta", "dim" | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
| markup = [ | markup = [ | ||||||
|     "bold", "underline", "linequote", "quote", "rainbow" |     "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 being references to other post_ids, like >>34 or >>0 for OP | ||||||
| quotes = re.compile(">>([0-9]+)") | quotes = re.compile(">>([0-9]+)") | ||||||
| bold = re.compile(r"\*{2}(.{1,20})\*{2}") | bold = re.compile(r"(?<!\\)\*{2}(.+?)(?<!\\)\*{2}") | ||||||
| underline = re.compile(r"__(.{1,20})__") | 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): | 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")]: |         for segment in [s.strip() for s in paragraph.split("\n")]: | ||||||
|             if not segment: |             if not segment: | ||||||
|                 continue |                 continue | ||||||
|             segment = quotes.sub(lambda m: "[quote: %s]" % m.group(1), segment) |             _fp = segment.find(" ") | ||||||
|             segment = bold.sub(lambda m: "[bold: %s]" % m.group(1), segment) |             first_word =  segment[:_fp] if _fp != -1 else segment | ||||||
|             segment = underline.sub(lambda m: "[underline: %s]" % m.group(1), segment) |             if segment.startswith(">") and not quotes.search(first_word): | ||||||
|             if segment.startswith(">"): |  | ||||||
|                 if sanitize_linequotes: |                 if sanitize_linequotes: | ||||||
|                     inner = segment.replace("]", "\\]") |                     inner = segment.replace("]", "\\]") | ||||||
|                 else: |                 else: | ||||||
|                     inner = segment |                     inner = apply_directives(segment) | ||||||
|                 segment = "[linequote: %s]" % inner |                 pg += "[linequote: %s]" % inner | ||||||
|                 # pg = pg[0:-1] |  | ||||||
|                 pg += segment |  | ||||||
|             else: |             else: | ||||||
|                 pg += segment + " " |                 pg += apply_directives(segment) + " " | ||||||
|         result.append(pg.strip()) |         result.append(pg.strip()) | ||||||
|     return result |     return result | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user