Coder Social home page Coder Social logo

text-markdown's Introduction

WARNING

This Readme is from the original version of Markdown; not all of the information contained herein is applicable to Test::Markdown the CPAN module that includes this file. See the module's POD file for more information.

Install locally

This module uses Module::Install. Run this before starting to work and install other dependencies

cpanm Module::Install Module::Install::CheckConflicts

And then

cpanm --installdeps . 
perl Makefile.PL

Of course, all this is solved if you just download it from CPAN using, for instance,

cpanm Text::Markdown

Markdown

Version 1.0.1 - Tue 14 Dec 2004

by John Gruber
http://daringfireball.net/

Introduction

Markdown is a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML).

Thus, "Markdown" is two things: a plain text markup syntax, and a software tool, written in Perl, that converts the plain text markup to HTML.

Markdown works both as a Movable Type plug-in and as a standalone Perl script -- which means it can also be used as a text filter in BBEdit (or any other application that supporst filters written in Perl).

Full documentation of Markdown's syntax and configuration options is available on the web: http://daringfireball.net/projects/markdown/. (Note: this readme file is formatted in Markdown.)

Installation and Requirements

Markdown requires Perl 5.6.0 or later. Welcome to the 21st Century. Markdown also requires the standard Perl library module Digest::MD5.

Movable Type

Markdown works with Movable Type version 2.6 or later (including MT 3.0 or later).

  1. Copy the "Markdown.pl" file into your Movable Type "plugins" directory. The "plugins" directory should be in the same directory as "mt.cgi"; if the "plugins" directory doesn't already exist, use your FTP program to create it. Your installation should look like this:

    (mt home)/plugins/Markdown.pl
    
  2. Once installed, Markdown will appear as an option in Movable Type's Text Formatting pop-up menu. This is selectable on a per-post basis. Markdown translates your posts to HTML when you publish; the posts themselves are stored in your MT database in Markdown format.

  3. If you also install SmartyPants 1.5 (or later), Markdown will offer a second text formatting option: "Markdown with SmartyPants". This option is the same as the regular "Markdown" formatter, except that automatically uses SmartyPants to create typographically correct curly quotes, em-dashes, and ellipses. See the SmartyPants web page for more information: http://daringfireball.net/projects/smartypants/

  4. To make Markdown (or "Markdown with SmartyPants") your default text formatting option for new posts, go to Weblog Config -> Preferences.

Note that by default, Markdown produces XHTML output. To configure Markdown to produce HTML 4 output, see "Configuration", below.

Blosxom

Markdown works with Blosxom version 2.x.

  1. Rename the "Markdown.pl" plug-in to "Markdown" (case is important). Movable Type requires plug-ins to have a ".pl" extension; Blosxom forbids it.

  2. Copy the "Markdown" plug-in file to your Blosxom plug-ins folder. If you're not sure where your Blosxom plug-ins folder is, see the Blosxom documentation for information.

  3. That's it. The entries in your weblog will now automatically be processed by Markdown.

  4. If you'd like to apply Markdown formatting only to certain posts, rather than all of them, see Jason Clark's instructions for using Markdown in conjunction with Blosxom's Meta plugin:

    http://jclark.org/weblog/WebDev/Blosxom/Markdown.html

BBEdit

Markdown works with BBEdit 6.1 or later on Mac OS X. (It also works with BBEdit 5.1 or later and MacPerl 5.6.1 on Mac OS 8.6 or later.)

  1. Copy the "Markdown.pl" file to appropriate filters folder in your "BBEdit Support" folder. On Mac OS X, this should be:

    BBEdit Support/Unix Support/Unix Filters/
    

    See the BBEdit documentation for more details on the location of these folders.

    You can rename "Markdown.pl" to whatever you wish.

  2. That's it. To use Markdown, select some text in a BBEdit document, then choose Markdown from the Filters sub-menu in the "#!" menu, or the Filters floating palette

Configuration

By default, Markdown produces XHTML output for tags with empty elements. E.g.:

<br />

Markdown can be configured to produce HTML-style tags; e.g.:

<br>

Movable Type

You need to use a special MTMarkdownOptions container tag in each Movable Type template where you want HTML 4-style output:

<MTMarkdownOptions output='html4'>
    ... put your entry content here ...
</MTMarkdownOptions>

The easiest way to use MTMarkdownOptions is probably to put the opening tag right after your <body> tag, and the closing tag right before </body>.

To suppress Markdown processing in a particular template, i.e. to publish the raw Markdown-formatted text without translation into (X)HTML, set the output attribute to 'raw':

<MTMarkdownOptions output='raw'>
    ... put your entry content here ...
</MTMarkdownOptions>

Command-Line

Use the --html4tags command-line switch to produce HTML output from a Unix-style command line. E.g.:

% perl Markdown.pl --html4tags foo.text

Type perldoc Markdown.pl, or read the POD documentation within the Markdown.pl source code for more information.

Bugs

To file bug reports or feature requests please send email to: [email protected].

Version History

1.0.1 (14 Dec 2004):

  • Changed the syntax rules for code blocks and spans. Previously, backslash escapes for special Markdown characters were processed everywhere other than within inline HTML tags. Now, the contents of code blocks and spans are no longer processed for backslash escapes. This means that code blocks and spans are now treated literally, with no special rules to worry about regarding backslashes.

    NOTE: This changes the syntax from all previous versions of Markdown. Code blocks and spans involving backslash characters will now generate different output than before.

  • Tweaked the rules for link definitions so that they must occur within three spaces of the left margin. Thus if you indent a link definition by four spaces or a tab, it will now be a code block.

       [a]: /url/  "Indented 3 spaces, this is a link def"
    
        [b]: /url/  "Indented 4 spaces, this is a code block"
    

    IMPORTANT: This may affect existing Markdown content if it contains link definitions indented by 4 or more spaces.

  • Added >, +, and - to the list of backslash-escapable characters. These should have been done when these characters were added as unordered list item markers.

  • Trailing spaces and tabs following HTML comments and <hr/> tags are now ignored.

  • Inline links using < and > URL delimiters weren't working:

    like [this](<http://example.com/>)
    
  • Added a bit of tolerance for trailing spaces and tabs after Markdown hr's.

  • Fixed bug where auto-links were being processed within code spans:

    like this: `<http://example.com/>`
    
  • Sort-of fixed a bug where lines in the middle of hard-wrapped paragraphs, which lines look like the start of a list item, would accidentally trigger the creation of a list. E.g. a paragraph that looked like this:

    I recommend upgrading to version
    8. Oops, now this line is treated
    as a sub-list.
    

    This is fixed for top-level lists, but it can still happen for sub-lists. E.g., the following list item will not be parsed properly:

    +	I recommend upgrading to version
    	8. Oops, now this line is treated
    	as a sub-list.
    

    Given Markdown's list-creation rules, I'm not sure this can be fixed.

  • Standalone HTML comments are now handled; previously, they'd get wrapped in a spurious <p> tag.

  • Fix for horizontal rules preceded by 2 or 3 spaces.

  • <hr> HTML tags in must occur within three spaces of left margin. (With 4 spaces or a tab, they should be code blocks, but weren't before this fix.)

  • Capitalized "With" in "Markdown With SmartyPants" for consistency with the same string label in SmartyPants.pl. (This fix is specific to the MT plug-in interface.)

  • Auto-linked email address can now optionally contain a 'mailto:' protocol. I.e. these are equivalent:

  • Fixed annoying bug where nested lists would wind up with spurious (and invalid) <p> tags.

  • You can now write empty links:

    [like this]()
    

    and they'll be turned into anchor tags with empty href attributes. This should have worked before, but didn't.

  • ***this*** and ___this___ are now turned into

    <strong><em>this</em></strong>
    

    Instead of

    <strong><em>this</strong></em>
    

    which isn't valid. (Thanks to Michel Fortin for the fix.)

  • Added a new substitution in _EncodeCode(): s/$/$/g; This is only for the benefit of Blosxom users, because Blosxom (sometimes?) interpolates Perl scalars in your article bodies.

  • Fixed problem for links defined with urls that include parens, e.g.:

    [1]: http://sources.wikipedia.org/wiki/Middle_East_Policy_(Chomsky)
    

    "Chomsky" was being erroneously treated as the URL's title.

  • At some point during 1.0's beta cycle, I changed every sub's argument fetching from this idiom:

    my $text = shift;
    

    to:

    my $text = shift || return '';
    

    The idea was to keep Markdown from doing any work in a sub if the input was empty. This introduced a bug, though: if the input to any function was the single-character string "0", it would also evaluate as false and return immediately. How silly. Now fixed.

Donations

Donations to support Markdown's development are happily accepted. See: http://daringfireball.net/projects/markdown/ for details.

Copyright and License

Copyright (c) 2003-2004 John Gruber
http://daringfireball.net/
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name "Markdown" nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.

text-markdown's People

Contributors

bobtfish avatar daleevans avatar dandv avatar genehack avatar jj avatar manwar avatar roy-tate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

text-markdown's Issues

Lists + verbatim code blocks with indentation get nested <pre> tags

Hello,

I've found (the hard way) an input case that seems to break the Text::Markdown handling of verbatim blocks. I'm using Text::Markdown 1.000031 (latest from CPAN) with Perl 5.16.0 on x86_64.

Here's what happens to a simple illustrative test:

For illustration purposes:                                                      

    Pre block                                                                      
    More pre content                                                               
        Indented region                                                            

        Indented, with blank line between

The output becomes (as expected):

<p>For illustration purposes:</p>

<pre><code>Pre block
More pre content
    Indented region

    Indented, with blank line between
</code></pre>

Now, for the bug. Wrapping the original in a list with a hanging indent gives for input:

1. List item                                                                       
    Continued text from previous region.                                           

        Pre block                                                                  
        More pre content . . .                                                     
            Indented region                                                        

                Indented, with blank line between

But the output is inconsistent with the previous:

<ol>
<li><p>List item
Continued text from previous region.</p>

<pre><code>Pre block
More pre content . . .
    Indented region


<pre><code>Indented, with blank line between
</code></pre>

</code></pre></li>
</ol>

Note the nested <pre> and <code> tags. This doesn't seem correct to me, but please feel free to convince me otherwise. It also seems to happen without the hanging indent on the list item, for reference.

I've done a bit of digging around in the Text::Markdown source, but I haven't found anything that looks like it would cause this yet. Then again, I'm still learning Perl, and hence it is entirely conceivable that I'm missing something. If someone else could take a look at this and reproduce/fix, it would be appreciated!

Thanks.

Problems with emphasis inside words.

There seem to be a number of problems when emphasis markers (* or ** or _ or __) occur inside of words. Specific examples:

  • "a*b*" should produce "a<em>b</em>" but instead produces "a*b*".
  • "a**b**" should produce "a<strong>b</strong>" but instead produces "a*<em>b</em>*".
  • However: "*b*a" and "**b**a" behave as expected.

Underscores appear to be broken in the same ways (and correct in the same ways) as asterisks.

Makefile.PL fails with no '.' in @INC

On current bleadperl with no '.' in @inc:

Output from '/home/cpan4/install/bin/perl Makefile.PL':

Can't locate inc/Module/Install.pm in @INC (you may need to install the inc::Module::Install module) (@INC contains: /tmp/CPAN-Reporter-lib-oHTJ /home/cpan4/install/lib/perl5/site_perl/5.26.0/x86_64-linux-thread-multi-ld /home/cpan4/install/lib/perl5/site_perl/5.26.0 /home/cpan4/install/lib/perl5/5.26.0/x86_64-linux-thread-multi-ld /home/cpan4/install/lib/perl5/5.26.0) at Makefile.PL line 2.
BEGIN failed--compilation aborted at Makefile.PL line 2.

------------------------------
PREREQUISITES
------------------------------

Prerequisite modules loaded:

configure_requires:

    Module              Need Have   
    ------------------- ---- -------
    ExtUtils::MakeMaker 6.42 7.25_01


------------------------------
ENVIRONMENT AND OTHER CONTEXT
------------------------------

Environment variables:

    AUTOMATED_TESTING = 1
    HARNESS_OPTIONS = j3
    LANG = en_US.UTF-8
    PATH = /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
    PERL = /home/cpan4/install/bin/perl
    PERL5LIB = 
    PERL5OPT = -I/tmp/CPAN-Reporter-lib-oHTJ -MDevel::Autoflush
    PERL5_CPANPLUS_IS_RUNNING = 16984
    PERL5_CPAN_IS_EXECUTING = /home/cpan4/.cpan/build/Text-Markdown-1.000031-0/Makefile.PL
    PERL5_CPAN_IS_RUNNING = 16984
    PERL5_CPAN_IS_RUNNING_IN_RECURSION = 18389,16984
    PERL_AUTOINSTALL = --defaultdeps
    PERL_CR_SMOKER_CURRENT = Contenticious-0.391
    PERL_CR_SMOKER_RUNONCE = 1
    PERL_EXTUTILS_AUTOINSTALL = --defaultdeps
    PERL_MM_USE_DEFAULT = 1
    PERL_USE_UNSAFE_INC = 0
    SHELL = /bin/bash
    TERM = putty-256color

Perl special variables (and OS-specific diagnostics, for MSWin32):

    $^X = /home/cpan4/install/bin/perl
    $UID/$EUID = 1005 / 1005
    $GID = 1005 1005
    $EGID = 1005 1005

Perl module toolchain versions installed:

    Module              Have      
    ------------------- ----------
    CPAN                2.16      
    CPAN::Meta          2.150010  
    Cwd                 3.67      
    ExtUtils::CBuilder  0.280225  
    ExtUtils::Command   7.25_01   
    ExtUtils::Install   2.04      
    ExtUtils::MakeMaker 7.25_01   
    ExtUtils::Manifest  1.70      
    ExtUtils::ParseXS   3.34      
    File::Spec          3.67      
    JSON                2.90      
    JSON::PP            2.27400_02
    Module::Build       0.4222    
    Module::Signature   n/a       
    Parse::CPAN::Meta   2.150010  
    Test::Harness       3.38      
    Test::More          1.302073  
    YAML                1.23      
    YAML::Syck          1.29      
    version             0.9917    


--

Summary of my perl5 (revision 5 version 26 subversion 0) configuration:
  Commit id: 1b92e6949b737e92f61827f9c92afce9218e30ba
  Platform:
    osname=linux
    osvers=3.16.0-4-amd64
    archname=x86_64-linux-thread-multi-ld
    uname='linux digitalis 3.16.0-4-amd64 #1 smp debian 3.16.36-1+deb8u2 (2016-10-19) x86_64 gnulinux '
    config_args='-Dusedevel -DDEBUGGING -Dusethreads -Duselongdouble -Duse64bitall -Doptimize=-O3 -Dprefix=/home/cpan4/install -Uversiononly -Uman1dir -Uman3dir -des'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=define
    uselongdouble=define
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-O3 -g'
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='4.9.2'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='long double'
    nvsize=16
    Off_t='off_t'
    lseeksize=8
    alignbytes=16
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /lib64 /usr/lib64
    libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.19.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.19'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O3 -g -L/usr/local/lib -fstack-protector-strong'


Characteristics of this binary (from libperl): 
  Compile-time options:
    DEBUGGING
    HAS_TIMES
    MULTIPLICITY
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_IMPLICIT_CONTEXT
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_TRACK_MEMPOOL
    PERL_USE_DEVEL
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_ITHREADS
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_LONG_DOUBLE
    USE_PERLIO
    USE_PERL_ATOF
    USE_REENTRANT_API
  Built under linux
  Compiled at Mar 31 2017 23:44:13
  %ENV:
    PERL="/home/cpan4/install/bin/perl"
    PERL5LIB=""
    PERL5OPT=""
    PERL5_CPANPLUS_IS_RUNNING="16984"
    PERL5_CPAN_IS_EXECUTING="/home/cpan4/.cpan/build/Text-Markdown-1.000031-0/Makefile.PL"
    PERL5_CPAN_IS_RUNNING="16984"
    PERL5_CPAN_IS_RUNNING_IN_RECURSION="18389,16984"
    PERL_AUTOINSTALL="--defaultdeps"
    PERL_CR_SMOKER_CURRENT="Contenticious-0.391"
    PERL_CR_SMOKER_RUNONCE="1"
    PERL_EXTUTILS_AUTOINSTALL="--defaultdeps"
    PERL_MM_USE_DEFAULT="1"
    PERL_USE_UNSAFE_INC="0"
  @INC:
    /home/cpan4/install/lib/perl5/site_perl/5.26.0/x86_64-linux-thread-multi-ld
    /home/cpan4/install/lib/perl5/site_perl/5.26.0
    /home/cpan4/install/lib/perl5/5.26.0/x86_64-linux-thread-multi-ld
    /home/cpan4/install/lib/perl5/5.26.0

I want the option to use when you do not have to write html.

How can I automatically escape HTML content using Markdown?

If escape in advance, are doubly escaped code block... :/

Text::Markdown::markdown( encode_entities($text, '<>&"') )

I want the option to use when you do not have to write html.

If the Markdow not support, implementation is difficult.

Please tell me if there is any good way.

Links within two block elements not expanded

I have this:

<div markdown="1">
<div>
[Link in two divs](http://example.com/)
</div>
</div>

I think that should be expanded to:

<div>
<div>
<p><a href="http://example.com/">Link in two divs</a></p>
</div>
</div>

But I end up with:

<div>
<div>
[Link in two divs](http://example.com/)
</div>
</div>

Failing test file attached

links.t.gz

long lines cause memory use to balloon

perl -e 'use Text::Markdown "markdown"; markdown("a" x 6000000)'

This command feeds 6 mb of data to markdown, which takes 200 mb of memory to process it.

Most of the problem seems to be caused by the very long line. The same amount of data in short lines needs only 45 mb of memory.

perl -e 'use Text::Markdown "markdown"; markdown("a\n" x 3000000)'

While doubling the length of the single line nearly doubled the memory needed, to 385 mb.

perl -e 'use Text::Markdown "markdown"; markdown("a" x 12000000)'

This was observed in the wild, where a spammer DOSed a wiki by entering a single 6 mb long line into it.

Is this project alive

Hi, @bobtfish !

Are you still here?

As far as I can see, this project is no longer maintained by you, is it still possible to contact you?

Ill-formed HTML for lists and blockquotes

Migrated from https://rt.cpan.org/Ticket/Display.html?id=37945

Sat Jul 26 2008 http://gmcmanus.myopenid.com/ - Ticket created

Consider the following markdown document:

- a
> b

markdown produces this ill-formed HTML:

<p><ul>
<li>a</p>

<blockquote>
<p>b</li>
</ul></p>
</blockquote>

I'm using Text-Markdown-1.0.21 (debian sid package
libtext-markdown-perl_1.0.21-1), with perl v5.10.0.

Sat Jul 26 2008 BOBTFISH - Correspondence added

On 26 Jul 2008, at 05:19, http://gmcmanus.myopenid.com/ via RT wrote:

Severity: Important

I'm using Text-Markdown-1.0.21 (debian sid package
libtext-markdown-perl_1.0.21-1), with perl v5.10.0.

This is a known bug, and all implementations which trace themselves
back to John Gruber's original one exhibit this behavior:

http://babelmark.bobtfish.net/?markdown=+-+a%0D%0A%3E+++b%0D%
0A&normalize=on&src=1&dest=2

It's also somewhat hard to fix with the current parser - i.e. I think
it's a re-write of significant bits of the code. :( I'll leave the
ticket open however, as it's on my todo list some day...

Cheers
Tom

prompt_script has been deprecated

prompt_script() in Makefile.PL has been deprecated (and removed) since Module::Install 0.72. Please consider replacing it with install_script(), maybe with or without preceding prompt(). Thanks

Incorrectly double-nested list item

The following markdown:

List items can wrap across multiple lines:

  * This is the first bullet,
    which is longer than one line.
  * This is the second bullet,
which is also on multiple lines.
* You don't have to indent the bullet
But there must be a space following the bullet marker.

By my reckoning this should be a single UL element with three list items. But Text::Markdown puts the third one inside another UL.

Nested links permitted

Currently it is possible to create nested links. Based on the W3C standard, A elements cannot contain other elements:

http://www.w3.org/TR/html4/struct/links.html#h-12.2.2

Here is a test case:

use strict;
use warnings;

use Test::More tests => 1;
use Text::Markdown;

my $markdown = q{

  1. * x
  2. * %61%6C%65%72%74%28%27%78%73%73%27%29%3B](onmouseover=eval(unescape(this.innerHTML.substr(4)))//)
    };

my $output = Text::Markdown::markdown( $markdown );

unlike( $output,
qr{<a\shref="<a\shref=}xms,
'No nested links found in output' );

Option to disable p-tags around final HTML.

Currently there's always

tags around the resulting HTML, no matter if there are any newlines in the markdown or not. Please provide an option to disable this behavior so the resulting HTML can be embedded in websites more easily.

Incorrectly finding blockquotes embedded in fenced code blocks

If you have a fenced code block with a line which begins with a "<" character, it gets incorrectly treated as a blockquote. This can be reproduced with the latest Text::Markdown from Github.

The following code demonstrates the problem (you'll need to remove the backslash from the start of the fenced code block markers before running the code):

#!/usr/bin/perl -w

use Text::Markdown 'markdown';

my $text = <<END;
\```
this is a fenced code block
> which contains a line which looks like a blockquote because it begins with greater-than
\```
END

my $html = markdown($text);

print "Text::Markdown version: " . Text::Markdown->VERSION . "\n\n";
print $html;

Remove the ">" to see the rendering as it should be.

Edge case for angle bracket encoding

Migrated from https://rt.cpan.org/Ticket/Display.html?id=33443

Input: x<max(a,b)

The Dingus says: <p>x<max(a,b)</p>

Expect: <p>x&lt;max(a,b)</p>

Mon Mar 17 2008 BOBTFISH - Correspondence added

This is expected. Angle encoding only happens when the angle bracket is
surrounded by whitespace.

That said, I'll have a look at what the other Markdown implementations
do here, and if they're all behaving differently, I may do that..

http://babelmark.bobtfish.net/?markdown=x%3Cmax%28a%2Cb%29

links not translated in markdown processed block level elements

When you have a block level element with the markdown attribute set it does not translate the markdown links to html links.

e.g.

<div class="someclass" markdown="1">
[Google][1]
</div>
[1]: http://www.google.ca     

Does not translate properly.
This is because it is hashing the html blocks before it is grabbing the link definitions, if you strip the link definitions first then it works properly. I'm not sure if this would cause other issues (maybe stripping something out that looks like a link reference that is in a block level element that is not markdown processed? It seems okay in our testing so far.

patch (I hope the formatting doesn't get too messed up):

--- a/Markdown.pm       2011-04-15 14:29:44.794861807 -0500
+++ b/Markdown.pm       2011-04-15 14:29:50.848690220 -0500
@@ -232,11 +232,11 @@

$text = $self->_CleanUpDoc($text);

+    $text = $self->_StripLinkDefinitions($text);
+    
     # Turn block-level HTML elements into hash entries, and interpret markdown in them if they have a 'markdown="1"' attribute
     $text = $self->_HashHTMLBlocks($text, {interpret_markdown_on_attribute => 1});

-    $text = $self->_StripLinkDefinitions($text);
-
     $text = $self->_RunBlockGamut($text, {wrap_in_p_tags => 1});

     $text = $self->_UnescapeSpecialChars($text);

Document the fact that the output always ends with *one* newline

One justification for this behavior could be:

Note that L<Text::Markdown> ensures that the output always ends with B<one>
newline. The fact that multiple newlines are collapsed into one makese sense,
because this is the behavior of HTML towards whispace. The fact that there's
always a newline at the end makes sense again, given that the output will always
be nested in a B<block>-level element, be it a C<< <p> >> (most often),
C<< <table> C>>, or C<< <div> >> (when passing HTML through).

Fwd: Entity conversion glitch?

Migrated from https://rt.cpan.org/Ticket/Display.html?id=32951

Tue Feb 05 14:42:30 2008 BOBTFISH - Ticket created

Subject:    Fwd: Entity conversion glitch?
Date:   Tue, 5 Feb 2008 19:41:18 +0000
To: [email protected]
From:   Tomas Doran <[email protected]>

Begin forwarded message:

> From: Petite Abeille <[email protected]>
> Date: 3 February 2008 17:22:31 GMT
> To: [email protected]
> Subject: Entity conversion glitch?
> Reply-To: "Discussion related to Markdown." <markdown- 
> [email protected]>
>
> Hello,
>
> Given the following text:
>
> under a license from AT&T; however, others were based on BSD instead.
>
> Daring Fireball's Markdown Dingus produces:
>
> <p>under a license from AT&T; however, others were based on BSD 
> instead.</p>
>
> Note how the '&' is not escaped to '&amp;'.
>
> Bug? Feature?
>
> Thanks in advance.
>
> Kind regards,
>
> PA.
> _______________________________________________
> Markdown-Discuss mailing list
> [email protected]
> http://six.pairlist.net/mailman/listinfo/markdown-discuss

Tue Feb 05 14:57:31 2008 BOBTFISH - Correspondence added

[email protected] said:

I would say this is a minor bug, and an interesting edge case as well.
The cause is the semi-colon following the `T`. `&T;` looks like an
html entity. If you remove the semicolon, the `&` is properly
converted to `&amp;`.

In python-markdown, you can escape the `&` and you will get the expected
output:

under a license from AT\&T; however, others were based on BSD instead.

becomes:

<p>under a license from AT&amp;T; however, others were based on BSD
instead.
</p>

Unfortunately, this does not seem to work in the other implementations.

Tue Feb 05 14:57:45 2008 BOBTFISH - Status changed from 'new' to 'open'

Tue Feb 05 15:03:13 2008 BOBTFISH - Requestor [email protected] added

Tue Feb 05 15:04:18 2008 BOBTFISH - Requestor BOBTFISH deleted

Tue Feb 05 15:05:37 2008 BOBTFISH - Taken

Tue Feb 05 15:10:25 2008 BOBTFISH - Correspondence added

Hiya

I've added this as a bug to Text::Markdown on rt.cpan.org from your
Markdown mailing list post.

Are you using original Markdown.pl, one of the CPAN versions, or a
non-perl version? Are you using the perl version (any of them), and so
is this relevant to you - or would you like me to remove you from the
ticket requestor field?

Tue Feb 05 15:16:16 2008 [email protected] - Correspondence added

Subject:    Re: [rt.cpan.org #32951] Fwd: Entity conversion glitch? 
Date:   Tue, 5 Feb 2008 21:15:39 +0100
To: [email protected]
From:   Petite Abeille <[email protected]>

Download (untitled) [text/plain 752b] 
Hi Tomas,

On Feb 5, 2008, at 9:10 PM, Tomas Doran via RT wrote:

> <URL: http://rt.cpan.org/Ticket/Display.html?id=32951 >
>
> I've added this as a bug to Text::Markdown on rt.cpan.org from your
> Markdown mailing list post.
>
> Are you using original Markdown.pl, one of the CPAN versions, or a
> non-perl version? Are you using the perl version (any of them),

Nope. Using Niklas Frykholm's Lua implementation:

http://www.frykholm.se/files/markdown.lua

> and so is this relevant to you - or would you like me to remove you 
> from the
> ticket requestor field?

Considering that the perl implementation is the 'canonical' one, 
people tend to mimic its, hmmm, idiosyncrasies :)

You can keep me posted.

Thanks for filing a bug :)

Cheers,

PA.

Tue Feb 05 15:29:03 2008 BOBTFISH - Correspondence added

Subject:    Re: [rt.cpan.org #32951] Fwd: Entity conversion glitch? 
Date:   Tue, 5 Feb 2008 20:26:49 +0000
To: [email protected]
From:   Tomas Doran <[email protected]>

On 5 Feb 2008, at 20:16, [email protected] via RT wrote:
>> Are you using original Markdown.pl, one of the CPAN versions, or a
>> non-perl version? Are you using the perl version (any of them),
>
> Nope. Using Niklas Frykholm's Lua implementation:
>
> http://www.frykholm.se/files/markdown.lua

Cool, I've heard a lot of good things about the lua, I must play one 
day.

> Considering that the perl implementation is the 'canonical' one,
> people tend to mimic its, hmmm, idiosyncrasies :)

Yep :)

I maintain Text::Markdown and Text::MultiMarkdown on CPAN.

I've got Text::MultiMarkdown to the point where can passes John's 
entire test suite + more of MultiMarkdown's test suite than the 
'real' MultiMarkdown passes, and I'm planning to merge the two 
modules shortly..

I'm also currently trying different ways of implementing the markdown 
parser, as I think that it can be:

a) A helluva lot quicker
b) Smarter, to deal with edge cases like this and the list item 
example posted recently to the list.
c) Pluggable - everyone and their dog wants a 'markdown like' 
language - but no two groups want exactly the same feature set. 
Rather than go the way of having a zillion 'options' (which is gonna 
make your code suck at best + still be inflexible), I'm trying to 
build a modular parser, so that people who care to do so can plug 
together various markdown (and/or other elements) and produce a 
markdown like language that works for them..

> You can keep me posted.

Will do :)

Cheers
Tom

Tue Mar 04 20:40:37 2008 JOEY - Correspondence added

Speaking of speed, I did this benchmark of 3 versions. The 1.0.1 and
1.0.2b8 versions are the non-cpan perl versions of markdown. I
benchmarked simply markdowning "foo".

markdown 1.0.1
markdown: 3 wallclock secs ( 3.37 usr + 0.02 sys = 3.39 CPU) @
2949.85/s (n=10000)

markdown 1.0.2~b8
markdown: 6 wallclock secs ( 6.08 usr + 0.00 sys = 6.08 CPU) @
1644.74/s (n=10000)

CPAN Text::Markdown 1.0.16
markdown: 11 wallclock secs (10.48 usr + 0.01 sys = 10.49 CPU) @
953.29/s (n=10000)

Wed Mar 05 04:03:54 2008 BOBTFISH - Correspondence added

Subject:    Re: [rt.cpan.org #32951] Fwd: Entity conversion glitch? 
Date:   Wed, 5 Mar 2008 09:03:09 +0000
To: [email protected]
From:   Tomas Doran <[email protected]>

Download (untitled) [text/plain 434b] 

On 5 Mar 2008, at 01:40, Joey Hess via RT wrote:
>
> CPAN Text::Markdown 1.0.16
> markdown: 11 wallclock secs (10.48 usr + 0.01 sys = 10.49 CPU) @
> 953.29/s (n=10000)
>

From profiling Text::Markdown, *most* of the time is spent in 
Text::Balanced, which does the HTML Entity conversion.

This was introduced in the latest version of Markdown that John 
wrote, to fix a number of the bugs with the HTML encoding.

Cheers
Tom

Link attributes not working on numeric reference links

Numeric link references work, but if you add a link attribute it is not included in the output. Implicitly named link references have this same bug.

Example input :

This is a footnote style [reference link][1] with an attribute. 

[1]: http://domain.com "reference" target=_blank

Expected output:
<p>This is a footnote style <a href="http://domain.com" title="reference" target="_blank">reference link</a> with an attribute.</p>

Actual output:
<p>This is a footnote style <a href="http://domain.com" title="reference">reference link</a> with an attribute.</p>

Github flavoured markdown

Hiya

I've written some code to support github flavoured markdown, if you want to add it to Text::Markdown:

http://github.github.com/github-flavored-markdown/

sub gfm{
    my $content = shift // '';
    my %extractions;

    # Extract pre blocks
    my $extract = sub {
        my $content = shift // '';
        my $md5 = md5_hex($content);
        $extractions{$md5} = $content;
        return "{gfm-extraction-$md5}";
    };

    $content =~ s{(<pre>.*?</pre>)}{$extract->($1)}ges;

    # prevent foo_bar_baz from ending up with an italic word in the middle
    my $underscores = sub {
        my $content = shift // '';
        $content =~ s/_/\\_/g
            if ( $content =~ tr/_// ) > 1;
        return $content;
    };

    $content =~ s/(^(?! {4}|\t)\w+_\w+_\w[\w_]*)/$underscores->($1)/gem;

    # in very clear cases, let newlines become <br /> tags
    my $brs = sub {
        my $content = shift // '';
        return $content if $content =~ /\n\n/;
        $content =~ s/^\s+//;
        $content =~ s/\s+$//;
        return "$content  \n";
    };

    $content =~ s/^([\w<][^\n]*\n+)/$brs->($1)/gexm;

    # Insert pre block extractions
    $content =~ s/\{gfm-extraction-([0-9a-f]{32})\}/$extractions{$1}/ge;

    return $content;
}

code elements expand `[[ ... ]]` to links

block-code elements expand [[...]] to links and at least I didn't find any way around it (HTML entities as markdown escapes are escaped correctly). This makes quoting shell-scripts using bash/zsh-test-expressions impossible.

URL autoreplacing is non-standard, only works unexpected if URLs are surrounded by '<>'URLs are not auto-replaced

observation

$text =~ s{<((https?|ftp):[^'">\s]+)>}{<a href="$1">$1</a>}gi;
tells that there is an autoreplacement of https?|ftp URLs which is a nice feature. I stumpled upon the implementation as I tried to extend URL replacement in comments in
os-autoinst/openQA#490 where I assumed Perl::Markdown does not have this feature at all.

current behavior

Researching code I found out that it actually does but only if the URL is surrounded by '<>' which was unexpected. IIUC standard markdown does not foresee URL auto-replacement for http/https/ftp, see http://daringfireball.net/projects/markdown/syntax

expected behavior

  • EITHER: no replacement
  • OR: replacement of all http[s]?|ftp references without the '<>' in all cases where it stands free and is not already part of a HTML block (or verbatim block, of course)
  • OR: support the common [link](url) syntax

suggestion

Replace
$text =~ s{<((https?|ftp):[^'">\s]+)>}{<a href="$1">$1</a>}gi;
by
$text =~ s{(?<!['"(])((http[s]?|ftp)://[^\s]*)}{<a href="$1">$1</a>}gi;

  • using "negative look-behind" to not match within quotes or html-hrefs or as part of a markdown link (using []() syntax)
  • matching also references without '<>'

Problems with cpanm or perl makefile.PL

There seems to be some stuff missing in the repo

Can't locate inc/Module/Install.pm in @INC (you may need to install the inc::Module::Install module) (@INC contains: /home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0/x86_64-linux /home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0 /home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/lib/5.20.0/x86_64-linux /home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/lib/5.20.0 .) at Makefile.PL line 2.
BEGIN failed--compilation aborted at Makefile.PL line 2.

Any script I can run to install it beforehand?

Incorrectly parses certain embedded html

The following html (which was embedded in a large markdown file):

<!-- comment -->
<style>
</style>
<div>
</div>
<!-- comment -->

is incorrectly converted into:

<!-- comment -->
<style>
</style>

1c450cea280a1905a112821f9f56ad46

<!-- comment -->

This occurs for any HTML block following the style section (ie, form, p).

checksum error

Text-Markdown-1.000031.tar.gz has a checksum error when installing via command line cpan or untaring the file from cpan.org.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.