def parse_headers(source_lines, props, toplevel=False): """Parse the metadata stored in the content headers.""" new_data = []; out = new_data.append iterative_source = IteratorParser(source_lines) for line in iterative_source: if line.startswith(':') and line.find(':', 2) != -1: marker = line.find(':', 2) prop, value = line[1:marker], line[marker+1:].strip() if prop.lower().startswith('x-'): _strip_prop = True else: _strip_prop = False if not _strip_prop: out(line) while True: try: line = iterative_source.next() if not _strip_prop: out(line) except: break sline = line.strip() if sline and not (sline.startswith(':') and \ sline.find(':', 2) != -1): value += ' ' + sline else: iterative_source.push(line) if not _strip_prop: del new_data[-1] break prop = prop.lower() if prop in props: oldvalue = props[prop] if isinstance(oldvalue, list): oldvalue.append(value) else: props[prop] = [oldvalue, value] else: props[prop] = value else: out(line) # re.sub('(?sm)\[\[# (.*?)\]\]', render_includes, content) return new_data, props
def parse_headers(source_lines, props, toplevel=False): """Parse the metadata stored in the content headers.""" new_data = [] out = new_data.append iterative_source = IteratorParser(source_lines) for line in iterative_source: if line.startswith(':') and line.find(':', 2) != -1: marker = line.find(':', 2) prop, value = line[1:marker], line[marker + 1:].strip() if prop.lower().startswith('x-'): _strip_prop = True else: _strip_prop = False if not _strip_prop: out(line) while True: try: line = iterative_source.next() if not _strip_prop: out(line) except: break sline = line.strip() if sline and not (sline.startswith(':') and \ sline.find(':', 2) != -1): value += ' ' + sline else: iterative_source.push(line) if not _strip_prop: del new_data[-1] break prop = prop.lower() if prop in props: oldvalue = props[prop] if isinstance(oldvalue, list): oldvalue.append(value) else: props[prop] = [oldvalue, value] else: props[prop] = value else: out(line) # re.sub('(?sm)\[\[# (.*?)\]\]', render_includes, content) return new_data, props
def convert(content): """Convert certain characters to prettier typographical syntax.""" # Remember: the order of the replacements matter... content = content.replace( '"', '"').replace( ' -->', 'HTML-COMMENT-ELEMENT-CLOSE').replace( '->', '→').replace( '<-', '←').replace( '---', '–').replace( '--', '—').replace( '<<', '«').replace( '>>', '»').replace( '(C)','©').replace( # hmz, why am i promoting ipr? ;p '(c)','©').replace( '(tm)','™').replace( '(TM)','™').replace( '(r)','®').replace( '(R)','®').replace( '...', '…').replace( 'HTML-COMMENT-ELEMENT-CLOSE', ' -->') icontent = IteratorParser(content) content = [] _scurly = _dcurly = False _space = True _apply = False index = 0 prev = '' while True: try: char = icontent.next() except StopIteration: break if not (_scurly or _dcurly) and _space: if char == "'": _scurly = index + 1 elif char == '"': _dcurly = index + 1 if _scurly and (_scurly != index + 1) and char == "'" and prev != '\\': try: n = icontent.next() if n in PUNCTUATION or n.isspace(): _apply = True icontent.push(n) except: _apply = True if _apply: content[_scurly - 1] = '‘' char = '’' _scurly = False _apply = False if _dcurly and (_dcurly != index + 1) and char == '"' and prev != '\\': try: n = icontent.next() if n in PUNCTUATION or n.isspace(): _apply = True icontent.push(n) except: _apply = True if _apply: content[_dcurly - 1] = '“' char = '”' _dcurly = False _apply = False content.append(char) prev = char index += 1 if char.isspace(): _space = True else: _space = False content = ''.join(content).replace('"', '"') content = replace_plexlinks(render_plexlink, content) # perhaps === heading === stylee ? return content
def convert(content): """Convert certain characters to prettier typographical syntax.""" # remember: the order of the replacements matter... content = content.replace( # '<', '<').replace( # '>', '>').replace( '"', '"').replace( # '&', '&').replace( ' -->', 'HTML-COMMENT-ELEMENT-CLOSE' ).replace('->', '→').replace('<-', '←').replace( '---', '–').replace('--', '—').replace( '<<', '«').replace('>>', '»').replace( '(C)', '©').replace( # hmz, why am i promoting ipr? ;p '(c)', '©').replace('(tm)', '™').replace( '(TM)', '™').replace('(r)', '®').replace( '(R)', '®').replace('...', '…').replace( 'HTML-COMMENT-ELEMENT-CLOSE', ' -->') icontent = IteratorParser(content) content = [] _scurly = _dcurly = False _space = True _apply = False index = 0 prev = '' while True: try: char = icontent.next() except StopIteration: break if not (_scurly or _dcurly) and _space: if char == "'": _scurly = index + 1 elif char == '"': _dcurly = index + 1 if _scurly and (_scurly != index + 1) and char == "'" and prev != '\\': try: n = icontent.next() if n in PUNCTUATION or n.isspace(): _apply = True icontent.push(n) except: _apply = True if _apply: content[_scurly - 1] = '‘' char = '’' _scurly = False _apply = False if _dcurly and (_dcurly != index + 1) and char == '"' and prev != '\\': try: n = icontent.next() if n in PUNCTUATION or n.isspace(): _apply = True icontent.push(n) except: _apply = True if _apply: content[_dcurly - 1] = '“' char = '”' _dcurly = False _apply = False content.append(char) prev = char index += 1 if char.isspace(): _space = True else: _space = False content = ''.join(content).replace('"', '"') content = replace_plexlinks(render_plexlink, content) # perhaps === heading === stylee ? return content
def convert(content): """Convert certain characters to prettier typographical syntax.""" # remember: the order of the replacements matter... content = ( content.replace( # '<', '<').replace( # '>', '>').replace( """, '"', ) .replace( # '&', '&').replace( " -->", "HTML-COMMENT-ELEMENT-CLOSE", ) .replace("->", "→") .replace("<-", "←") .replace("---", "–") .replace("--", "—") .replace("<<", "«") .replace(">>", "»") .replace("(C)", "©") .replace("(c)", "©") # hmz, why am i promoting ipr? ;p .replace("(tm)", "™") .replace("(TM)", "™") .replace("(r)", "®") .replace("(R)", "®") .replace("...", "…") .replace("HTML-COMMENT-ELEMENT-CLOSE", " -->") ) icontent = IteratorParser(content) content = [] _scurly = _dcurly = False _space = True _apply = False index = 0 prev = "" while True: try: char = icontent.next() except StopIteration: break if not (_scurly or _dcurly) and _space: if char == "'": _scurly = index + 1 elif char == '"': _dcurly = index + 1 if _scurly and (_scurly != index + 1) and char == "'" and prev != "\\": try: n = icontent.next() if n in PUNCTUATION or n.isspace(): _apply = True icontent.push(n) except: _apply = True if _apply: content[_scurly - 1] = "‘" char = "’" _scurly = False _apply = False if _dcurly and (_dcurly != index + 1) and char == '"' and prev != "\\": try: n = icontent.next() if n in PUNCTUATION or n.isspace(): _apply = True icontent.push(n) except: _apply = True if _apply: content[_dcurly - 1] = "“" char = "”" _dcurly = False _apply = False content.append(char) prev = char index += 1 if char.isspace(): _space = True else: _space = False content = "".join(content).replace('"', """) content = replace_plexlinks(render_plexlink, content) # perhaps === heading === stylee ? return content