{"id":1520,"date":"2024-04-08T02:36:54","date_gmt":"2024-04-08T05:36:54","guid":{"rendered":"https:\/\/benjaminray.com\/codebase\/?p=1520"},"modified":"2024-08-04T00:17:39","modified_gmt":"2024-08-04T03:17:39","slug":"post-guidelines","status":"publish","type":"post","link":"https:\/\/benjaminray.com\/codebase\/post-guidelines\/","title":{"rendered":"Post Guidelines"},"content":{"rendered":"<h2>Background<\/h2>\n<p>This site uses <a href=\"https:\/\/www.markdownguide.org\/basic-syntax\/\" target=\"_blank\" rel=\"noopener noreferrer\">Markdown<\/a> for simplified input. Specifically, it adheres to the <a href=\"https:\/\/spec.commonmark.org\/spec\" target=\"_blank\" rel=\"noopener noreferrer\">CommonMark spec<\/a>. Code is highlighted using <a href=\"https:\/\/highlightjs.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">highlight.js<\/a>.<\/p>\n<h2>Adding Code to a Post<\/h2>\n<p>There are two ways to add code to a post using Markdown. The most flexible way is to use &quot;code fences&quot;, which entails wrapping the code between two lines containing 3 backticks (```) or tildes (~~~). Code fences allow you to add a language hint to tell the highlighter what language is in use. The other way to add code to a post is to indent the code with 4 spaces or a tab, which is covered further down in this post. The indent\/space option doesn't allow language hinting.<\/p>\n<h3>Code fences using backticks or tildes:<\/h3>\n<div class=\"row-io\">\n<div>\n<pre><code class=\"language-nohighlight\">```\nvar s = 'some test';\nconsole.log(s);\n```\n<\/code><\/pre>\n<\/p><\/div>\n<div>\n<pre><code>var s = 'new test';\nalert('test');\n<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"row-io\">\n<div>\n<pre><code class=\"language-nohighlight\">~~~\nvar s = 'some test';\nconsole.log(s);\n~~~\n<\/code><\/pre>\n<\/p><\/div>\n<div>\n<pre><code>var s = 'new test';\nalert('test');\n<\/code><\/pre>\n<\/div>\n<\/div>\n<h4>Language Hinting<\/h4>\n<p>highlight.js doesn't always correctly guess the language of a piece of code. Limiting the set of loaded languages (like I have on this site) helps with that, as it will only use languages that are loaded. But the safest option is to add a language hint to all code fences:<\/p>\n<div class=\"row-io\">\n<div>\n<pre><code class=\"language-nohighlight\">```vb\n' Some VB code\nDim str as String\nstr = New String(&quot;test&quot;)\n```\n<\/code><\/pre>\n<\/p><\/div>\n<div>\n<pre><code class=\"language-vb\">' Some VB code\nDim str as String\nstr = New String(&quot;test&quot;)\n<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"row-io\">\n<div>\n<pre><code class=\"language-nohighlight\">~~~json\n{\n  &quot;firstName&quot;: &quot;John&quot;,\n  &quot;lastName&quot;: &quot;Smith&quot;,\n  &quot;age&quot;: 25\n}\n~~~\n<\/code><\/pre>\n<\/p><\/div>\n<div>\n<pre><code class=\"language-json\">{\n  &quot;firstName&quot;: &quot;John&quot;,\n  &quot;lastName&quot;: &quot;Smith&quot;,\n  &quot;age&quot;: 25\n}\n<\/code><\/pre>\n<\/div>\n<\/div>\n<p>To include code fence characters in a code block, say if you wanted to demonstrate how to write a code fence, you would wrap the code fence in a different number of backticks or tildes. Use the special language hint &quot;nohighlight&quot; if you don't want the output highlighted as code.<\/p>\n<div class=\"row-io\">\n<div>\n<pre><code class=\"language-nohighlight\">````nohighlight\n```\nconst s = 'some test';\nconsole.log(s);\n```\n````\n<\/code><\/pre>\n<\/p><\/div>\n<div>\n<pre><code class=\"language-nohighlight\">```\nconst s = 'some test';\nconsole.log(s);\n```\n<\/code><\/pre>\n<\/div>\n<\/div>\n<p>Note: You can always manually create the &lt;pre&gt;&lt;code&gt;...&lt;\/code&gt;&lt;\/pre&gt; tags, including the language hint (prefixed with &quot;language-&quot;). But there's really no need to do that since you can wrap anything in a code fence.<\/p>\n<div class=\"row-io\">\n<div>\n<pre>\n&#x3C;pre&#x3E;&#x3C;code class=&#x22;language-vb&#x22;&#x3E;\nProtected Sub PrepareEmailModal\n    If Not Page.IsPostBack Then\n        &#x27; Populate email modal with some defaults\n        ucModal.Subject = &#x22;Some Default Subject&#x22;\n        ucModal.Body = &#x22;Some body content&#x22;\n    End If\nEnd Sub\n&#x3C;\/code&#x3E;&#x3C;\/pre&#x3E;\n<\/pre>\n<\/p><\/div>\n<div>\n<pre><code class=\"language-vb\">Protected Sub PrepareEmailModal\n    If Not Page.IsPostBack Then\n        ' Populate email modal with some defaults\n        ucModal.Subject = \"Some Default Subject\"\n        ucModal.Body = \"Some body content\"\n    End If\nEnd Sub<\/code><\/pre>\n<\/div>\n<\/div>\n<h3>Indented Code Blocks Using Tab or 4 Spaces:<\/h3>\n<p>You can also add code by indenting it with a tab or 4 spaces. However, you cannot add a language hint to indented code blocks, so code fences are preferred.<\/p>\n<div class=\"row-io\">\n<div>\n<pre><code class=\"language-nohighlight\">    const s = 'some test';\n    console.log(s);\n<\/code><\/pre>\n<\/p><\/div>\n<div>\n<pre><code>const s = 'some test';\nconsole.log(s);\n<\/code><\/pre>\n<\/div>\n<\/div>\n<h2>Inline Code and Backtick Characters<\/h2>\n<p>To add inline code, wrap it in single backticks `like this`, which gives you a code tag <code>like this<\/code>. (Note: Inline code tags are not syntax highlighted.)<\/p>\n<p>To include a backtick inside a piece of inline code <code>like ` this<\/code>, open and close the code tag with a different number of backticks than appear in the inline code. E.g. If you want to display 1 backtick in the inline code, open\/close with two or more. To include two in a row in the code tag, open\/close with 1 or 3 or more. ``this`works`` becomes <code>this`works<\/code>, `this``works` becomes <code>this``works<\/code>, etc.<br \/>\nMore info here: <a href=\"https:\/\/meta.stackexchange.com\/a\/70679\/286764\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/meta.stackexchange.com\/a\/70679\/286764<\/a><\/p>\n<p>To include a backtick in regular text (not in inline code), escape it with a backslash: \\`<\/p>\n<h2>Code Fences and &lt;Code&gt; Tags Without Syntax Highlighting<\/h2>\n<p>To exclude a code fence from syntax highlighting, use the language hint <code>nohighlight<\/code>. E.g.:<\/p>\n<div class=\"row-io\">\n<div>\n<pre><code class=\"language-nohighlight\">```nohighlight\nconst someString = 'new test';\nalert(someString);\n```\n<\/code><\/pre>\n<\/p><\/div>\n<div>\n<pre><code class=\"language-nohighlight\">const someString = 'new test';\nalert(someString);\n<\/code><\/pre>\n<\/div>\n<\/div>\n<p>To exclude a &lt;code&gt; tag from syntax highlighting, use the class <code>nohighlight<\/code>. E.g.:<\/p>\n<div class=\"row-io\">\n<div>\n<pre>\n&lt;pre&gt;\n  &lt;code class=&quot;nohighlight&quot;&gt;\n    Some stuff inside a PRE tag\n  &lt;\/code&gt;\n&lt;\/pre&gt;\n<\/pre>\n<\/p><\/div>\n<div>\n<pre><code class=\"language-nohighlight\">Some stuff inside a PRE tag<\/code><\/pre>\n<\/div>\n<\/div>\n<h2>Custom Attributes<\/h2>\n<div class=\"row-io\">\n<div>\n<pre><code class=\"language-nohighlight\">```js title=&quot;Custom Title Attribute&quot;\nconst someString = 'new test';\nalert(someString);\n```\n<\/code><\/pre>\n<\/p><\/div>\n<div>\n<pre><code class=\"language-js\">const someString = 'new test';\nalert(someString);\n<\/code><\/pre>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Background This site uses Markdown for simplified input. Specifically, it adheres to the CommonMark spec. Code is highlighted using highlight.js. Adding Code to a Post There are two ways to  [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-1520","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"acf":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9GNjN-ow","jetpack_likes_enabled":false,"_links":{"self":[{"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/posts\/1520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/comments?post=1520"}],"version-history":[{"count":97,"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/posts\/1520\/revisions"}],"predecessor-version":[{"id":2053,"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/posts\/1520\/revisions\/2053"}],"wp:attachment":[{"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/media?parent=1520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/categories?post=1520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/tags?post=1520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}