Parse description of the book.

    Args:
        html_chunk (obj): HTMLElement containing slice of the page with details.

    Returns:
        str/None: Description as string or None if not found.
187774
def _parse_description(html_chunk):
    
    description_tag = html_chunk.match(
        ["div", {"class": "kniha_detail_text"}],
        "p"
    )

    if not description_tag:
        return None

    description = get_first_content(description_tag)
    description = description.replace("<br />", "\n")
    description = description.replace("<br/>", "\n")

    return dhtmlparser.removeTags(description).strip()
3750
def _parse_summary(tag, parser, parent):
    
    summary = DocElement(tag, parser, parent)
    parent.docstring.append(summary)
488128
def _parse_title_url(html_chunk):
    
    title = html_chunk.find("div", {"class": "comment"})

    if not title:
        return _parse_alt_title(html_chunk), None

    title = title[0].find("h2")
    if not title:
        return _parse_alt_title(html_chunk), None

    # look for the url of the book if present
    url = None
    url_tag = title[0].find("a")
    if url_tag:
        url = url_tag[0].params.get("href", None)
        title = url_tag

    return title[0].getContent(), normalize_url(BASE_URL, url)
283084
def parse(text: str) -> Docstring:
    
    ret = Docstring()
    if not text:
        return ret

    # Clean according to PEP-0257
    text = inspect.cleandoc(text)

    # Find first title and split on its position
    match = _titles_re.search(text)
    if match:
        desc_chunk = text[: match.start()]
        meta_chunk = text[match.start() :]
    else:
        desc_chunk = text
        meta_chunk = ""

    # Break description into short and long parts
    parts = desc_chunk.split("\n", 1)
    ret.short_description = parts[0] or None
    if len(parts) > 1:
        long_desc_chunk = parts[1] or ""
        ret.blank_after_short_description = long_desc_chunk.startswith("\n")
        ret.blank_after_long_description = long_desc_chunk.endswith("\n\n")
        ret.long_description = long_desc_chunk.strip() or None

    # Split by sections determined by titles
    matches = list(_titles_re.finditer(meta_chunk))
    if not matches:
        return ret
    splits = []
    for j in range(len(matches) - 1):
        splits.append((matches[j].end(), matches[j + 1].start()))
    splits.append((matches[-1].end(), len(meta_chunk)))

    chunks = {}
    for j, (start, end) in enumerate(splits):
        title = matches[j].group(1)
        if title not in _valid:
            continue
        chunks[title] = meta_chunk[start:end].strip("\n")
    if not chunks:
        return ret

    # Add elements from each chunk
    for title, chunk in chunks.items():
        # Determine indent
        indent_match = re.search(r"^\s+", chunk)
        if not indent_match:
            raise ParseError(f'Can\'t infer indent from "{chunk}"')
        indent = indent_match.group()

        # Check for returns/yeilds (only one element)
        if _sections[title] in ("returns", "yields"):
            part = inspect.cleandoc(chunk)
            ret.meta.append(_build_meta(part, title))
            continue

        # Split based on lines which have exactly that indent
        _re = "^" + indent + r"(?=\S)"
        c_matches = list(re.finditer(_re, chunk, flags=re.M))
        if not c_matches:
            raise ParseError(f'No specification for "{title}": "{chunk}"')
        c_splits = []
        for j in range(len(c_matches) - 1):
            c_splits.append((c_matches[j].end(), c_matches[j + 1].start()))
        c_splits.append((c_matches[-1].end(), len(chunk)))
        for j, (start, end) in enumerate(c_splits):
            part = chunk[start:end].strip("\n")
            ret.meta.append(_build_meta(part, title))

    return ret
893
async def read_message(self) -> Optional[Data]:
        
        frame = await self.read_data_frame(max_size=self.max_size)

        # A close frame was received.
        if frame is None:
            return None

        if frame.opcode == OP_TEXT:
            text = True
        elif frame.opcode == OP_BINARY:
            text = False
        else:  # frame.opcode == OP_CONT
            raise WebSocketProtocolError("Unexpected opcode")

        # Shortcut for the common case - no fragmentation
        if frame.fin:
            return frame.data.decode("utf-8") if text else frame.data

        # 5.4. Fragmentation
        chunks: List[Data] = []
        max_size = self.max_size
        if text:
            decoder_factory = codecs.getincrementaldecoder("utf-8")
            # https://github.com/python/typeshed/pull/2752
            decoder = decoder_factory(errors="strict")  # type: ignore
            if max_size is None:

                def append(frame: Frame) -> None:
                    nonlocal chunks
                    chunks.append(decoder.decode(frame.data, frame.fin))

            else:

                def append(frame: Frame) -> None:
                    nonlocal chunks, max_size
                    chunks.append(decoder.decode(frame.data, frame.fin))
                    max_size -= len(frame.data)

        else:
            if max_size is None:

                def append(frame: Frame) -> None:
                    nonlocal chunks
                    chunks.append(frame.data)

            else:

                def append(frame: Frame) -> None:
                    nonlocal chunks, max_size
                    chunks.append(frame.data)
                    max_size -= len(frame.data)

        append(frame)

        while not frame.fin:
            frame = await self.read_data_frame(max_size=max_size)
            if frame is None:
                raise WebSocketProtocolError("Incomplete fragmented message")
            if frame.opcode != OP_CONT:
                raise WebSocketProtocolError("Unexpected opcode")
            append(frame)

        # mypy cannot figure out that chunks have the proper type.
        return ("" if text else b"").join(chunks)
1303200
def tag_details(tag, nodenames):
    
    details = {}

    details['type'] = tag.name
    details['ordinal'] = tag_ordinal(tag)

    # Ordinal value
    if tag_details_sibling_ordinal(tag):
        details['sibling_ordinal'] = tag_details_sibling_ordinal(tag)

    # Asset name
    if tag_details_asset(tag):
        details['asset'] = tag_details_asset(tag)

    object_id_tag = first(raw_parser.object_id(tag, pub_id_type= "doi"))
    if object_id_tag:
        details['component_doi'] = extract_component_doi(tag, nodenames)

    return details
921987
def get_html_titles(index_page):
    
    dom = dhtmlparser.parseString(index_page)

    title_tags = dom.find("title")

    return [
        SourceString(tag.getContent().strip(), "HTML")
        for tag in title_tags
        if tag.getContent().strip()
    ]
1217096
def parse(self, text, as_html=True):
        
        if not text:
            return text
        entity_text = self.get_text(text)

        if self.type == MessageEntityType.BOLD:
            if as_html:
                return markdown.hbold(entity_text)
            return markdown.bold(entity_text)
        elif self.type == MessageEntityType.ITALIC:
            if as_html:
                return markdown.hitalic(entity_text)
            return markdown.italic(entity_text)
        elif self.type == MessageEntityType.PRE:
            if as_html:
                return markdown.hpre(entity_text)
            return markdown.pre(entity_text)
        elif self.type == MessageEntityType.CODE:
            if as_html:
                return markdown.hcode(entity_text)
            return markdown.code(entity_text)
        elif self.type == MessageEntityType.URL:
            if as_html:
                return markdown.hlink(entity_text, entity_text)
            return markdown.link(entity_text, entity_text)
        elif self.type == MessageEntityType.TEXT_LINK:
            if as_html:
                return markdown.hlink(entity_text, self.url)
            return markdown.link(entity_text, self.url)
        elif self.type == MessageEntityType.TEXT_MENTION and self.user:
            return self.user.get_mention(entity_text)
        return entity_text
1118299
def _parse_alt_url(html_chunk):
    
    url_list = html_chunk.find("a", fn=has_param("href"))
    url_list = map(lambda x: x.params["href"], url_list)
    url_list = filter(lambda x: not x.startswith("autori/"), url_list)

    if not url_list:
        return None

    return normalize_url(BASE_URL, url_list[0])
1151414
def content_description(self) -> Optional[UnstructuredHeader]:
        """"""
        try:
            return cast(UnstructuredHeader, self[b'content-description'][0])
        except (KeyError, IndexError):
            return None
993594
def _process_book(html_chunk):
    
    title, book_url = _parse_title_url(html_chunk)

    # download page with details
    data = DOWNER.download(book_url)
    dom = dhtmlparser.parseString(
        handle_encodnig(data)
    )
    details = dom.find("div", {"id": "kniha_detail"})[0]

    # required parameters
    pub = Publication(
        title=title,
        authors=_parse_authors(html_chunk),
        price=_parse_price(details),
        publisher="CPress"
    )

    # optional parameters
    pub.optionals.URL = book_url
    pub.optionals.EAN = _parse_ean(details)
    pub.optionals.format = _parse_format(details)
    pub.optionals.pub_date = _parse_date(details)
    pub.optionals.description = _parse_description(details)

    return pub
208805
function parsePagesList(book) {
    var summary = book.getSummary();
    var glossary = book.getGlossary();
    var map = Immutable.OrderedMap();

    // Parse pages from summary
    return timing.measure(
        'parse.listPages',
        walkSummary(summary, function(article) {
            if (!article.isPage()) return;

            var filepath = article.getPath();

            // Is the page ignored?
            if (book.isContentFileIgnored(filepath)) return;

            return parseFilePage(book, filepath)
            .then(function(page) {
                // file doesn't exist
                if (!page) {
                    return;
                }

                map = map.set(filepath, page);
            });
        })
    )

    // Parse glossary
    .then(function() {
        var file = glossary.getFile();

        if (!file.exists()) {
            return;
        }

        return parseFilePage(book, file.getPath())
        .then(function(page) {
            // file doesn't exist
            if (!page) {
                return;
            }

            map = map.set(file.getPath(), page);
        });
    })

    .then(function() {
        return map;
    });
}
1073784
def extractFromHTML(html, blur=5):
    

    #html = html.encode('utf-8', errors='ignore')
    try:
        html = unicode(html, errors='ignore')
    except TypeError:
        pass
    assert isinstance(html, unicode)

    # Create memory file.
    _file = StringIO()

    # Convert html to text.
    f = formatter.AbstractFormatter(formatter.DumbWriter(_file))
    p = TextExtractor()
    p.pathBlur = blur
    p.feed(html)
    p.close()
    text = p.get_plaintext()

    # Remove stand-alone punctuation.
    text = re.sub("\s[\(\),;\.\?\!](?=\s)", " ", text).strip()

    # Compress whitespace.
    text = re.sub("[\n\s]+", " ", text).strip()

    # Remove consequetive dashes.
    text = re.sub("\-{2,}", "", text).strip()

    # Remove consequetive periods.
    text = re.sub("\.{2,}", "", text).strip()

    return text
161380
def get_description(cls) -> str:
        
        if cls.__doc__ is None:
            raise ValueError('No docstring found for {}'.format(cls.__name__))
        return cls.__doc__.strip()
463889
def parse_toc(html_content):
    
    from flask import current_app
    from veripress.model.toc import HtmlTocParser

    if current_app.config['SHOW_TOC']:
        toc_parser = HtmlTocParser()
        toc_parser.feed(html_content)
        toc_html = toc_parser.toc_html(
            depth=current_app.config['TOC_DEPTH'],
            lowest_level=current_app.config['TOC_LOWEST_LEVEL'])
        toc = toc_parser.toc(
            depth=current_app.config['TOC_DEPTH'],
            lowest_level=current_app.config['TOC_LOWEST_LEVEL'])
        return toc_parser.html, toc, toc_html
    else:
        return html_content, None, None
737505
def _parse_authors(html_chunk):
    
    authors = html_chunk.match(
        ["div", {"class": "comment"}],
        "h3",
        "a",
    )

    if not authors:
        return []

    authors = map(
        lambda x: Author(                            # create Author objects
            x.getContent().strip(),
            normalize_url(BASE_URL, x.params.get("href", None))
        ),
        authors
    )

    return filter(lambda x: x.name.strip(), authors)
445284
def _parse_description(self, description_text):
        """"""
        text = description_text
        text = text.strip()
        lines = text.split('\n')

        data = {}
        for line in lines:
            if ":" in line:
                idx = line.index(":")
                key = line[:idx]
                value = line[idx+1:].lstrip().rstrip()
                data[key] = value
            else:
                if isinstance(value, list) is False:
                    value = [value]
                value.append(line.lstrip().rstrip())
                data[key] = value
        return data