{"id":2131,"date":"2020-03-02T14:53:32","date_gmt":"2020-03-02T05:53:32","guid":{"rendered":"https:\/\/yuis-programming.com\/?p=2131"},"modified":"2021-07-18T11:06:42","modified_gmt":"2021-07-18T02:06:42","slug":"markdown%e3%81%a7%e3%82%af%e3%83%a9%e3%82%b9%e3%82%92%e8%bf%bd%e5%8a%a0%e3%81%a7%e3%81%8d%e3%82%8b%e3%82%88%e3%81%86%e3%81%ab%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/yuis-programming.com\/?p=2131","title":{"rendered":"Markdown\u3067\u30af\u30e9\u30b9\u3092\u8ffd\u52a0\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>Markdown\u3067\u306f\u69d8\u3005\u306aHTML\u306e\u305f\u3081\u306e\u30bf\u30b0\u304c\u4f7f\u3048\u307e\u3059\u304c\u3001\u305d\u306e\u4e2d\u3067\u3082\u30af\u30e9\u30b9\u30bf\u30b0(class)\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u3067\u3059\u3002Node.js\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u30e9\u30a4\u30d6\u30e9\u30ea\u3001markdown-it-container\u3092\u4f7f\u7528\u3057\u3066Markdown \u30af\u30e9\u30b9\u30bf\u30b0(class)\u30bf\u30b0\u3092\u4f7f\u7528\u53ef\u80fd\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>markdown-it-container\u3067Markdown\u3067CSS\u30af\u30e9\u30b9\u3092\u8ffd\u52a0\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n<pre><code>npm install markdown-it-container --save\n<\/code><\/pre>\n<p><img src=\"https:\/\/yuis.xsrv.jp\/data\/0wUwaA3EBb0D3j8SOceVdHqHvraze5qz.png\" alt=\"https:\/\/yuis.xsrv.jp\/data\/0wUwaA3EBb0D3j8SOceVdHqHvraze5qz.png\"><\/p>\n<p><a href=\"https:\/\/www.npmjs.com\/package\/markdown-it-container\">markdown-it-container &#8211; npm<\/a><\/p>\n<pre><code>\nvar md = require('markdown-it')();\n\nmd.use(require('markdown-it-container'), 'spoiler', {\n\n  validate: function(params) {\n    return params.trim().match(\/^spoiler\\s+(.*)$\/);\n  },\n\n  render: function (tokens, idx) {\n    var m = tokens[idx].info.trim().match(\/^spoiler\\s+(.*)$\/);\n\n    if (tokens[idx].nesting === 1) {\n      \/\/ opening tag\n      return '&lt;details&gt;&lt;summary&gt;' + m[1] + '&lt;\/summary&gt;\\n';\n\n    } else {\n      \/\/ closing tag\n      return '&lt;\/details&gt;\\n';\n    }\n  }\n});\n\nmd.use(require('markdown-it-container'), 'class', {\n\n  validate: function(params) {\n    return params.trim().match(\/^class\\s+(.*)$\/);\n  },\n\n  render: function (tokens, idx) {\n    var m = tokens[idx].info.trim().match(\/^class\\s+(.*)$\/);\n\n    if (tokens[idx].nesting === 1) {\n      \/\/ opening tag\n      return `&lt;div class=\"${m[1]}\"&gt;\\n`;\n\n    } else {\n      \/\/ closing tag\n      return '&lt;\/div&gt;\\n';\n    }\n  }\n});\n\nconsole.log(\"\\n\");\n\nconsole.log(md.render('::: spoiler click me\\n*contentcontent*\\n:::\\n'));\nconsole.log(md.render('::: spoiler \\n*contentcontent*\\n:::\\n'));\nconsole.log(md.render('::: spoiler\\n*contentcontent*\\n:::\\n'));\n\nconsole.log(md.render('::: class warning\\n*contentcontent*\\n:::\\n'));\nconsole.log(md.render('::: class info\\n*contentcontent*\\n:::\\n'));\n\nconsole.log(md.render('::: class note gray\\n*contentcontent*\\n:::\\n'));\n\nconsole.log(md.render('::: class note gray\\n# hoge \\n## hogehoge \\n\\something\\n:::\\n'));\n<\/code><\/pre>\n<p><img src=\"https:\/\/yuis.xsrv.jp\/images\/ss\/ShareX_ScreenShot_59e6eb12-2d3f-471b-a070-f35ae935e2c3.png\" alt=\"https:\/\/yuis.xsrv.jp\/images\/ss\/ShareX_ScreenShot_59e6eb12-2d3f-471b-a070-f35ae935e2c3.png\"><\/p>\n<pre><code>&lt;details&gt;&lt;summary&gt;click me&lt;\/summary&gt;\n&lt;em&gt;contentcontent&lt;\/em&gt;\n&lt;\/details&gt;\n\n::: spoiler\n&lt;em&gt;contentcontent&lt;\/em&gt;\n:::\n\n::: spoiler\n&lt;em&gt;contentcontent&lt;\/em&gt;\n:::\n\n&lt;div class=\"warning\"&gt;\n&lt;em&gt;contentcontent&lt;\/em&gt;\n&lt;\/div&gt;\n\n&lt;div class=\"info\"&gt;\n&lt;em&gt;contentcontent&lt;\/em&gt;\n&lt;\/div&gt;\n\n&lt;div class=\"note gray\"&gt;\n&lt;em&gt;contentcontent&lt;\/em&gt;\n&lt;\/div&gt;\n\n&lt;div class=\"note gray\"&gt;\n&lt;h1&gt;hoge&lt;\/h1&gt;\n&lt;h2&gt;hogehoge&lt;\/h2&gt;\nsomething\n&lt;\/div&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Markdown\u3067\u306f\u69d8\u3005\u306aHTML\u306e\u305f\u3081\u306e\u30bf\u30b0\u304c\u4f7f\u3048\u307e\u3059\u304c\u3001\u305d\u306e\u4e2d\u3067\u3082\u30af\u30e9\u30b9\u30bf\u30b0(class)\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5\u306b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[50],"tags":[],"acf":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8Rxwo-yn","_links":{"self":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts\/2131"}],"collection":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2131"}],"version-history":[{"count":2,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts\/2131\/revisions"}],"predecessor-version":[{"id":2425,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts\/2131\/revisions\/2425"}],"wp:attachment":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}