Markdown, specifically for the Notes field in a CKAN dataset
427820
def markdown(doc, title=True, template='short_documentation.md'):
    """"""

    from jinja2 import Environment, PackageLoader, select_autoescape
    env = Environment(
        loader=PackageLoader('metapack', 'support/templates')
        #autoescape=select_autoescape(['html', 'xml'])
    )

    context = display_context(doc)

    return env.get_template(template).render(**context)
338425
def markdown_editor(selector):
    
    return dict(
        selector=selector,
        extra_settings=mark_safe(simplejson.dumps(
            dict(previewParserPath=reverse('django_markdown_preview')))))
1042322
def extendMarkdown(self, md, md_globals):
        """"""
        md.inlinePatterns.add('del', SimpleTagPattern(DEL_RE, 'del'), '<not_strong')
        md.inlinePatterns.add('ins', SimpleTagPattern(INS_RE, 'ins'), '<not_strong')
        md.inlinePatterns.add('mark', SimpleTagPattern(MARK_RE, 'mark'), '<not_strong')
874069
def preprocess_notebook(ntbk, cr):
    

    # Iterate over cells in notebook
    for n in range(len(ntbk['cells'])):
        # Only process cells of type 'markdown'
        if ntbk['cells'][n]['cell_type'] == 'markdown':
            # Get text of markdown cell
            txt = ntbk['cells'][n]['source']
            # Replace links to online docs with sphinx cross-references
            txt = cr.substitute_url_with_ref(txt)
            # Replace current cell text with processed text
            ntbk['cells'][n]['source'] = txt
918443
def replace_markdown_cells(src, dst):
    

    # It is an error to attempt markdown replacement if src and dst
    # have different numbers of cells
    if len(src['cells']) != len(dst['cells']):
        raise ValueError('notebooks do not have the same number of cells')

    # Iterate over cells in src
    for n in range(len(src['cells'])):
        # It is an error to attempt markdown replacement if any
        # corresponding pair of cells have different type
        if src['cells'][n]['cell_type'] != dst['cells'][n]['cell_type']:
            raise ValueError('cell number %d of different type in src and dst')
        # If current src cell is a markdown cell, copy the src cell to
        # the dst cell
        if src['cells'][n]['cell_type'] == 'markdown':
            dst['cells'][n]['source'] = src['cells'][n]['source']
1308422
def markdown_to_notebook(infile, outfile):
    """"""

    # Read infile into a string
    with open(infile, 'r') as fin:
        str = fin.read()
    # Enclose the markdown within triple quotes and convert from
    # python to notebook
    str = '"""' + str + '"""'
    nb = py2jn.py_string_to_notebook(str)
    py2jn.tools.write_notebook(nb, outfile, nbver=4)
1173281
def _cldf2wld(dataset):
    """"""
    header = [f for f in dataset.dataset.lexeme_class.fieldnames() if f != 'ID']
    D = {0: ['lid'] + [h.lower() for h in header]}
    for idx, row in enumerate(dataset.objects['FormTable']):
        row = deepcopy(row)
        row['Segments'] = ' '.join(row['Segments'])
        D[idx + 1] = [row['ID']] + [row[h] for h in header]
    return D
248652
def _write_class_markdown_to_file(self, f, name, cls):
    
    # Build the list of class methods to document.
    methods = dict(self.get_class_members(name, cls))
    # Used later to check if any methods were called out in the class
    # docstring.
    num_methods = len(methods)
    try:
      self._write_docstring_markdown_to_file(f, "####", inspect.getdoc(cls),
                                             methods, {})
    except ValueError as e:
      raise ValueError(str(e) + " in class `%s`" % cls.__name__)

    # If some methods were not described, describe them now if they are
    # defined by the class itself (not inherited).  If NO methods were
    # described, describe all methods.
    #
    # TODO(touts): when all methods have been categorized make it an error
    # if some methods are not categorized.
    any_method_called_out = (len(methods) != num_methods)
    if any_method_called_out:
      other_methods = {n: m for n, m in methods.items() if n in cls.__dict__}
      if other_methods:
        print("\n#### Other Methods", file=f)
    else:
      other_methods = methods
    for name in sorted(other_methods):
      self._write_member_markdown_to_file(f, "####", *other_methods[name])
485742
def display_annotations(self):
        """"""
        for item in self.idx_annot:
            self.scene.removeItem(item)
        self.idx_annot = []
        for item in self.idx_annot_labels:
            self.scene.removeItem(item)
        self.idx_annot_labels = []
        self.highlight = None

        window_start = self.parent.value('window_start')
        window_length = self.parent.value('window_length')
        window_end = window_start + window_length
        y_distance = self.parent.value('y_distance')

        bookmarks = []
        events = []

        if self.parent.notes.annot is not None:
            if self.parent.value('annot_show'):
                bookmarks = self.parent.notes.annot.get_bookmarks()
                events = self.parent.notes.get_selected_events((window_start,
                                                                window_end))
        annotations = bookmarks + events

        for annot in annotations:

            if window_start <= annot['end'] and window_end >= annot['start']:

                mrk_start = max((annot['start'], window_start))
                mrk_end = min((annot['end'], window_end))
                if annot in bookmarks:
                    color = QColor(self.parent.value('annot_bookmark_color'))
                if annot in events:
                    color = convert_name_to_color(annot['name'])

                if logical_or(annot['chan'] == [''],
                              self.action['cross_chan_mrk'].isChecked()):
                    h_annot = len(self.idx_label) * y_distance

                    item = TextItem_with_BG(color.darker(200))
                    item.setText(annot['name'])
                    item.setPos(annot['start'],
                                len(self.idx_label) * y_distance)
                    item.setFlag(QGraphicsItem.ItemIgnoresTransformations)
                    item.setRotation(-90)
                    self.scene.addItem(item)
                    self.idx_annot_labels.append(item)
                    mrk_dur = amax((mrk_end - mrk_start, 
                                  self.parent.value('min_marker_display_dur')))

                    item = RectMarker(mrk_start, 0, mrk_dur,
                                      h_annot, zvalue=-8,
                                      color=color.lighter(120))

                    self.scene.addItem(item)
                    self.idx_annot.append(item)

                if annot['chan'] != ['']:
                    # find indices of channels with annotations
                    chan_idx_in_mrk = in1d(self.chan, annot['chan'])
                    y_annot = asarray(self.chan_pos)[chan_idx_in_mrk]
                    y_annot -= y_distance / 2
                    mrk_dur = amax((mrk_end - mrk_start, 
                                  self.parent.value('min_marker_display_dur')))

                    for y in y_annot:
                        item = RectMarker(mrk_start, y, mrk_dur,
                                          y_distance, zvalue=-7, color=color)
                        self.scene.addItem(item)
                        self.idx_annot.append(item)
381877
def markdown2html(markdown_text):
    '''
    
    '''
    html = markdown.markdown(
        markdown_text,
        extensions=[
            WikiLinkExtension(base_url='/wiki/', end_url=''),
            'markdown.extensions.extra',
            'markdown.extensions.toc',
            'markdown.extensions.codehilite',
            'markdown.extensions.meta'
        ]
    )
    han_biaodians = ['。', '，', '；', '、', '！', '？']
    for han_biaodian in han_biaodians:
        html = html.replace(han_biaodian + '\n', han_biaodian)
    return tornado.escape.xhtml_escape(html)
919132
function createMarkdownSlide( content, options ) {

		options = getSlidifyOptions( options );

		var notesMatch = content.split( new RegExp( options.notesSeparator, 'mgi' ) );

		if( notesMatch.length === 2 ) {
			content = notesMatch[0] + '<aside class="notes">' + marked(notesMatch[1].trim()) + '</aside>';
		}

		// prevent script end tags in the content from interfering
		// with parsing
		content = content.replace( /<\/script>/g, SCRIPT_END_PLACEHOLDER );

		return '<script type="text/template">' + content + '</script>';

	}
58136
def display_annotations(self):
        
        for rect in self.idx_annot:
            self.scene.removeItem(rect)
        self.idx_annot = []

        if self.parent.notes.annot is None:
            return

        bookmarks = []
        events = []
        if self.parent.value('annot_show'):
            bookmarks = self.parent.notes.annot.get_bookmarks()
            events = self.parent.notes.get_selected_events()

        annotations = bookmarks + events

        for annot in annotations:
            rect = QGraphicsRectItem(annot['start'],
                                     BARS['annot']['pos0'],
                                     annot['end'] - annot['start'],
                                     BARS['annot']['pos1'])
            self.scene.addItem(rect)

            if annot in bookmarks:
                color = self.parent.value('annot_bookmark_color')
            if annot in events:
                color = convert_name_to_color(annot['name'])

            rect.setPen(QPen(QColor(color), LINE_WIDTH))
            rect.setBrush(QBrush(QColor(color)))
            rect.setZValue(-5)
            self.idx_annot.append(rect)

        for epoch in self.parent.notes.annot.epochs:
            self.mark_stages(epoch['start'],
                             epoch['end'] - epoch['start'],
                             epoch['stage'])
            self.mark_quality(epoch['start'],
                              epoch['end'] - epoch['start'],
                              epoch['quality'])

        cycles = self.parent.notes.annot.rater.find('cycles')
        cyc_starts = [float(mrkr.text) for mrkr in cycles.findall('cyc_start')]
        cyc_ends = [float(mrkr.text) for mrkr in cycles.findall('cyc_end')]

        for mrkr in cyc_starts:
            self.mark_cycles(mrkr, 30) # TODO: better width solution
        for mrkr in cyc_ends:
            self.mark_cycles(mrkr, 30, end=True)
279159
def fields(markdown)
      fields = []
      if markdown.file
        fields.push(title: 'file',
                    value: markdown.file,
                    short: true)
      end
      if markdown.line
        fields.push(title: 'line',
                    value: markdown.line,
                    short: true)
      end
      fields
    end
687089
def maybe_render_markdown(string: str) -> Any:
    """"""
    if is_ipython_interpreter():  # pragma: no cover
        from IPython.display import Markdown  # type: ignore # noqa: E501

        return Markdown(string)
    else:
        return string
1261205
function addMdExts () {
  var args = Array.prototype.slice.call(arguments);
  return args.reduce(function (memo, item) {
    return memo.concat([
      item + '.md',
      item + '.mkdn',
      item + '.mdown',
      item + '.markdown'
    ]);
  }, []);
}
1007259
def _intermediary_to_markdown(tables, relationships):
    
    t = '\n'.join(t.to_markdown() for t in tables)
    r = '\n'.join(r.to_markdown() for r in relationships)
    return '{}\n{}'.format(t, r)
1095421
def note_adapter(obj, request):
    '''
    
    '''
    return {
        'note': obj.note,
        'type': obj.type,
        'language': obj.language,
        'markup': obj.markup
    }