forked from puppetlabs/puppet-strings
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(puppetlabs#223) Use code blocks as appropriate in Markdown
Sometimes data types, default values, and other code outputted in Markdown documentation is multiline. When that’s the case, it’s cleaner to use a code block (below) rather and inline code (`code`). ``` example code block with two lines ``` This updates the Markdown template code to use code blocks in many places if the code in question contains a newline. Thanks to @crazymind1337 for the example of a multiline type alias!
- Loading branch information
1 parent
f6d615c
commit d328411
Showing
9 changed files
with
116 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
# Helpers for rendering Markdown | ||
module PuppetStrings::Markdown::Helpers | ||
# Formats code as either inline or a block. | ||
# | ||
# Note that this does not do any escaping even if the code contains ` or ```. | ||
# | ||
# @param [String] code The code to format. | ||
# @param [Symbol] type The type of the code, e.g. :text, :puppet, or :ruby. | ||
# @param [String] block_prefix String to insert before if it’s a block. | ||
# @param [String] inline_prefix String to insert before if it’s inline. | ||
# @returns [String] Markdown | ||
def code_maybe_block(code, type: :puppet, block_prefix: "\n\n", inline_prefix: ' ') | ||
if code.include?("\n") | ||
"#{block_prefix}```#{type}\n#{code}\n```" | ||
else | ||
"#{inline_prefix}`#{code}`" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters