Upgrade to Pro — share decks privately, control downloads, hide ads and more …

LaravelでMarkdownをブラウザに表示する方法

SAW
October 30, 2019

 LaravelでMarkdownをブラウザに表示する方法

Web×PHP TechCafe 10月 の発表資料です。

SAW

October 30, 2019
Tweet

More Decks by SAW

Other Decks in Programming

Transcript

  1.  XIPBNJ w ࢯ໊Ճ౻फҰ࿠ ࡀ  ‣ େࡕࡏॅɾѪ஌ग़਎ ‣ ϋϯυϧωʔϜ4"8

    w 4/4ΞΧ΢ϯτ ‣ 5XJUUFS!B[VLJ@FBUFS ‣ (JU)VCB[VLJQFOHVJO w ॴଐגࣜձࣾ.4&/ ೥໨ 2 FreeBSD macOS Linux Vue.js
  2. DFCFNBSLEPXOͷಋೖํ๏ w $PNQPTFSܦ༝ͰΠϯετʔϧ ‣ composer require cebe/markdown w .BSLEPXOύʔαΫϥεΛಡΈࠐΈ ‣

    cebe\markdown\Markdown.BSLEPXOͷύʔαΫϥε ‣ cebe\markdown\GithubMarkdown(JU)VCॻࣜͷύʔαΫϥε ‣ cebe\markdown\MarkdownExtra.BSLEPXO&YUSBॻࣜͷύʔαΫϥε 5
  3. DFCFNBSLEPXOͷར༻ํ๏ w .BSLEPXOύʔαΫϥεͷಡΈࠐΈ ‣ use cebe\markdown\GithubMarkdown; w ύʔαΠϯελϯεͷੜ੒ ‣ new

    GithubMarkdown(); w )5.-ܗࣜʹม׵ ‣ $parser->parse($markdown); 6 <?php use cebe\markdown\GithubMarkdown; public class Md2Html { public static function convert($md) { $parser = new GithubMarkdown(); return $parser->parse($md); } }
  4. ιʔείʔυྫ 9 class Article extends Model { public function getBodyAttribute($value)

    { $parser = new GithubMarkdown(); $this->attributes[‘body’] = $parser->parse($value); } } class ArticleController extends Controller { public function index(Request $req, $id) { $article = Article::find($id); return view(‘article’, [ ‘article’ => $article ]); } } <h1> {{ $article->title }} </h1> <article> {!! $article->body !!} </article>