src/downshow.js
function processNode(node) {
    if (node.tagName === 'P' || node.tagName === 'DIV' || node.tagName === 'UL' || node.tagName === 'OL' || node.tagName === 'PRE')
      setContent(node, getContent(node), '\n\n', '\n\n');
    else if (node.tagName === 'BR')
      setContent(node, '\n\n');
    else if (node.tagName === 'HR')
      setContent(node, '\n***\n');
    else if (node.tagName === 'H1')
      setContent(node, nltrim(getContent(node)), '\n# ', '\n');
    else if (node.tagName === 'H2') 
      setContent(node, nltrim(getContent(node)), '\n## ', '\n');
    else if (node.tagName === 'H3')
      setContent(node, nltrim(getContent(node)), '\n### ', '\n');
    else if (node.tagName === 'H4') 
      setContent(node, nltrim(getContent(node)), '\n#### ', '\n');
    else if (node.tagName === 'H5') 
      setContent(node, nltrim(getContent(node)), '\n##### ', '\n');
    else if (node.tagName === 'H6')
      setContent(node, nltrim(getContent(node)), '\n###### ', '\n');
    else if (node.tagName === 'B' || node.tagName === 'STRONG')
      setContent(node, nltrim(getContent(node)), '**', '**');
    else if (node.tagName === 'I' || node.tagName === 'EM')
      setContent(node, nltrim(getContent(node)), '_', '_');
    else if (node.tagName === 'A') {
      var href = node.href ? nltrim(node.href) : '', text = nltrim(getContent(node)) || href, title = node.title ? nltrim(node.title) : '';
      if (href.length > 0)
        setContent(node, '[' + text + '](' + href + (title ? ' "' + title + '"' : '') + ')');
      else
        setContent(node, '');
    } else if (node.tagName === 'IMG') {
      var src = node.getAttribute('src') ? nltrim(node.getAttribute('src')) : '', alt = node.alt ? nltrim(node.alt) : '', caption = node.title ? nltrim(node.title) : '';
      if (src.length > 0)
        setContent(node, '![' + alt + '](' + src  + (caption ? ' "' + caption + '"' : '') + ')');
      else
        setContent(node, '');
    } else if (node.tagName === 'BLOCKQUOTE') {
      var block_content = getContent(node);
      if (block_content.length > 0)
        setContent(node, prefixBlock('> ', block_content), '\n\n', '\n\n');
      else
        setContent(node, '');
    } else if (node.tagName === 'CODE') {
      if (node._bfs_parent.tagName === 'PRE' && node._bfs_parent._bfs_parent !== null)
        setContent(node, prefixBlock('    ', getContent(node)));
      else
        setContent(node, nltrim(getContent(node)), '`', '`');
    } else if (node.tagName === 'LI') {
      var list_content = getContent(node);
      if (list_content.length > 0)
        if (node._bfs_parent.tagName === 'OL') 
          setContent(node, trim(prefixBlock('    ', list_content, true)), '1. ', '\n\n');
        else
          setContent(node, trim(prefixBlock('    ', list_content, true)), '- ', '\n\n');
      else
        setContent(node, '');
    } else 
      setContent(node, getContent(node));
  }
function processNode(node) {
    if (node.tagName === 'P' || node.tagName === 'DIV' || node.tagName === 'UL' || node.tagName === 'OL' || node.tagName === 'PRE')
      setContent(node, getContent(node), '\n\n', '\n\n');
    else if (node.tagName === 'BR')
      setContent(node, '\n\n');
    else if (node.tagName === 'HR')
      setContent(node, '\n***\n');
    else if (node.tagName === 'H1')
      setContent(node, nltrim(getContent(node)), '\n# ', '\n');
    else if (node.tagName === 'H2') 
      setContent(node, nltrim(getContent(node)), '\n## ', '\n');
    else if (node.tagName === 'H3')
      setContent(node, nltrim(getContent(node)), '\n### ', '\n');
    else if (node.tagName === 'H4') 
      setContent(node, nltrim(getContent(node)), '\n#### ', '\n');
    else if (node.tagName === 'H5') 
      setContent(node, nltrim(getContent(node)), '\n##### ', '\n');
    else if (node.tagName === 'H6')
      setContent(node, nltrim(getContent(node)), '\n###### ', '\n');
    else if (node.tagName === 'B' || node.tagName === 'STRONG')
      setContent(node, nltrim(getContent(node)), '**', '**');
    else if (node.tagName === 'I' || node.tagName === 'EM')
      setContent(node, nltrim(getContent(node)), '_', '_');
    else if (node.tagName === 'A') {
      var href = node.href ? nltrim(node.href) : '', text = nltrim(getContent(node)) || href, title = node.title ? nltrim(node.title) : '';
      if (href.length > 0)
        setContent(node, '[' + text + '](' + href + (title ? ' "' + title + '"' : '') + ')');
      else
        setContent(node, '');
    } else if (node.tagName === 'IMG') {
      var src = node.getAttribute('src') ? nltrim(node.getAttribute('src')) : '', alt = node.alt ? nltrim(node.alt) : '', caption = node.title ? nltrim(node.title) : '';
      if (src.length > 0)
        setContent(node, '![' + alt + '](' + src  + (caption ? ' "' + caption + '"' : '') + ')');
      else
        setContent(node, '');
    } else if (node.tagName === 'BLOCKQUOTE') {
      var block_content = getContent(node);
      if (block_content.length > 0)
        setContent(node, prefixBlock('> ', block_content), '\n\n', '\n\n');
      else
        setContent(node, '');
    } else if (node.tagName === 'CODE') {
      if (node._bfs_parent.tagName === 'PRE' && node._bfs_parent._bfs_parent !== null)
        setContent(node, prefixBlock('    ', getContent(node)));
      else
        setContent(node, nltrim(getContent(node)), '`', '`');
    } else if (node.tagName === 'LI') {
      var list_content = getContent(node);
      if (list_content.length > 0)
        if (node._bfs_parent.tagName === 'OL') 
          setContent(node, trim(prefixBlock('    ', list_content, true)), '1. ', '\n\n');
        else
          setContent(node, trim(prefixBlock('    ', list_content, true)), '- ', '\n\n');
      else
        setContent(node, '');
    } else 
      setContent(node, getContent(node));
  }
function processNode ( node ) { if ( node . tagName === 'P' || node . tagName === 'DIV' || node . tagName === 'UL' || node . tagName === 'OL' || node . tagName === 'PRE' ) setContent ( node , getContent ( node ) , '\n\n' , '\n\n' ) ; else if ( node . tagName === 'BR' ) setContent ( node , '\n\n' ) ; else if ( node . tagName === 'HR' ) setContent ( node , '\n***\n' ) ; else if ( node . tagName === 'H1' ) setContent ( node , nltrim ( getContent ( node ) ) , '\n# ' , '\n' ) ; else if ( node . tagName === 'H2' ) setContent ( node , nltrim ( getContent ( node ) ) , '\n## ' , '\n' ) ; else if ( node . tagName === 'H3' ) setContent ( node , nltrim ( getContent ( node ) ) , '\n### ' , '\n' ) ; else if ( node . tagName === 'H4' ) setContent ( node , nltrim ( getContent ( node ) ) , '\n#### ' , '\n' ) ; else if ( node . tagName === 'H5' ) setContent ( node , nltrim ( getContent ( node ) ) , '\n##### ' , '\n' ) ; else if ( node . tagName === 'H6' ) setContent ( node , nltrim ( getContent ( node ) ) , '\n###### ' , '\n' ) ; else if ( node . tagName === 'B' || node . tagName === 'STRONG' ) setContent ( node , nltrim ( getContent ( node ) ) , '**' , '**' ) ; else if ( node . tagName === 'I' || node . tagName === 'EM' ) setContent ( node , nltrim ( getContent ( node ) ) , '_' , '_' ) ; else if ( node . tagName === 'A' ) { var href = node . href ? nltrim ( node . href ) : '' , text = nltrim ( getContent ( node ) ) || href , title = node . title ? nltrim ( node . title ) : '' ; if ( href . length > 0 ) setContent ( node , '[' + text + '](' + href + ( title ? ' "' + title + '"' : '' ) + ')' ) ; else setContent ( node , '' ) ; } else if ( node . tagName === 'IMG' ) { var src = node . getAttribute ( 'src' ) ? nltrim ( node . getAttribute ( 'src' ) ) : '' , alt = node . alt ? nltrim ( node . alt ) : '' , caption = node . title ? nltrim ( node . title ) : '' ; if ( src . length > 0 ) setContent ( node , '![' + alt + '](' + src + ( caption ? ' "' + caption + '"' : '' ) + ')' ) ; else setContent ( node , '' ) ; } else if ( node . tagName === 'BLOCKQUOTE' ) { var block_content = getContent ( node ) ; if ( block_content . length > 0 ) setContent ( node , prefixBlock ( '> ' , block_content ) , '\n\n' , '\n\n' ) ; else setContent ( node , '' ) ; } else if ( node . tagName === 'CODE' ) { if ( node . _bfs_parent . tagName === 'PRE' && node . _bfs_parent . _bfs_parent !== null ) setContent ( node , prefixBlock ( '    ' , getContent ( node ) ) ) ; else setContent ( node , nltrim ( getContent ( node ) ) , '`' , '`' ) ; } else if ( node . tagName === 'LI' ) { var list_content = getContent ( node ) ; if ( list_content . length > 0 ) if ( node . _bfs_parent . tagName === 'OL' ) setContent ( node , trim ( prefixBlock ( '    ' , list_content , true ) ) , '1. ' , '\n\n' ) ; else setContent ( node , trim ( prefixBlock ( '    ' , list_content , true ) ) , '- ' , '\n\n' ) ; else setContent ( node , '' ) ; } else setContent ( node , getContent ( node ) ) ; }
Process a node in the DOM tree.
Process a node in the DOM tree .