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 an H1

This is an H2

This is an H6
'), 'text' => '# This is an H1 ## This is an H2 ###### This is an H6' }, 'em' => { 'html' => HTML::Entities::encode_entities('Emphasis or ephasis'), 'text' => '_emphasis_ or *emphasis*' }, 'strong' => { 'html' => HTML::Entities::encode_entities('Strong or strong'), 'text' => '**strong** or __strong__' }, 'list' => { 'html' => HTML::Entities::encode_entities('
  1. First
  2. Second
'), 'text' => '- First - Second 1. First 2. Second' }, 'image' => { 'html' => HTML::Entities::encode_entities(''), 'text' => '![Image Alt](https://duckduckgo.com/assets/badges/logo_square.64.png)' }, 'link' => { 'html' => HTML::Entities::encode_entities('This is an example inline link'), 'text' => '[This is an example inline link](http://www.duckduckgo.com "Example Title")' }, 'blockquote' => { 'html' => HTML::Entities::encode_entities('
This is the first level of quoting.
This is nested blockquote.
Back to the first level.
'), '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:
'.$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;