package DDG::Goodie::MarkdownCheatSheet; # ABSTRACT: Provide a cheatsheet for common Markdown syntax use strict; use DDG::Goodie; use HTML::Entities; zci answer_type => "markdown_cheat"; zci is_cached => 1; name "MarkdownCheatSheet"; description "Markdown cheat sheet"; source "http://daringfireball.net/projects/markdown/syntax"; code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/MarkdownCheatSheet.pm"; category "cheat_sheets"; topics "computing", "geek", "web_design"; primary_example_queries 'markdown help header', 'markdown cheat sheet h1', 'markdown syntax list'; secondary_example_queries 'markdown quick reference image', 'markdown guide headers'; triggers startend => ( 'markdown', 'md', 'markdown help', 'md help', 'markdown cheat sheet', 'md cheat sheet', 'markdown cheatsheet', 'md cheatsheet', 'markdown syntax', 'md syntax', 'markdown guide', 'md guide', 'markdown quick reference', 'md quick reference', 'markdown reference', 'md reference', ); attribution github => ["marianosimone", "Mariano Simone"]; # Base snippet definitions my %snippets = ( 'header' => { 'html' => HTML::Entities::encode_entities('
This is the first level of quoting.'), 'text' => '> This is the first level of quoting. > > > This is nested blockquote. > > Back to the first level.' } ); my %synonyms = ( 'header', ['h1', 'headers', 'h2', 'h3', 'h4', 'h5', 'h6', 'heading'], 'em', ['emphasis', 'emphasize', 'italic', 'italics'], 'strong', ['bold'], 'image', ['img', 'images', 'insert image'], 'link', ['a', 'href', 'links'], 'blockquote', ['quote', 'quotation'], 'list', ['lists', 'ordered list', 'unordered list', 'ul', 'ol', 'bullet', 'bullets'] ); # Add more mappings for each snippet foreach my $key (keys(%synonyms)) { foreach my $v (@{$synonyms{$key}}) { $snippets{$v} = $snippets{$key}; } } my $more_at = 'More at Daring Fireball'; sub make_html { my $element = $_[0]; return 'Markdown:This is nested blockquote.Back to the first level.
'.$snippets{$element}->{'text'}.'HTML:
'.$snippets{$element}->{'html'}.''.$more_at }; handle remainder => sub { return unless $_; my $requested = $snippets{$_}; return unless $requested; return heading => 'Markdown Cheat Sheet', html => make_html($_), answer => $snippets{$_}->{'text'} }; 1;