Answers.Body: <p>You can convert your Markdown text to HTML using <a href="https://www.yiiframework.com/doc/api/2.0/yii-helpers-markdown" rel="nofollow noreferrer">yii\helpers\Markdown</a>, which is what the <code>|md</code> Twig filter hooks into:</p>
  
  <pre class="lang-php prettyprint-override"><code>'transformer' =&gt; function(\craft\elements\Entry $entry) {
      return [
          'body' =&gt; \yii\helpers\Markdown::process((string)$entry-&gt;yourTextFieldHandle),
      ];
  },
  </code></pre>
  
  <p>If you want the equivalent of <code>|md('text', inlineOnly=true)</code> (where only inline elements are parsed – no <code>&lt;p&gt;</code> tags), call <code>processParagraph()</code> instead of <code>process()</code>.</p>
  
  <p>If you want to parse the copy as <a href="https://github.github.com/gfm/" rel="nofollow noreferrer">GitHub Flavored Markdown</a>, pass <code>'gfm'</code> as a second argument to <code>process()</code>:</p>
  
  <pre class="lang-php prettyprint-override"><code>'transformer' =&gt; function(\craft\elements\Entry $entry) {
      return [
          'body' =&gt; \yii\helpers\Markdown::process((string)$entry-&gt;yourTextFieldHandle, 'gfm'),
      ];
  },
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-21T23:18:32.897Z
Answers.Text: Thanks so much, this worked perfectly. I got something close to this but was looking for helpers within Craft. Didn't think to use Yii helpers. Thanks again!
Answers.UserDisplayName: Moucky
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-21T22:56:01.267Z
Answers.LastActivityDate: 2019-08-21T22:56:01.267Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I'm a little bit stuck using the Element API. I managed to get my JSON file going pretty easily which was great but I've reached a point where I want to include some formatted copy as it would be output using markdown in a .twig template, is this possible?</p>
  
Tags: <craft3><plugin-elementapi>
Title: Element API - Markdown in JSON
ThreadText: # Element API - Markdown in JSON
  
  (Asked by: username_0 on 2019-08-21)
  
  I'm a little bit stuck using the Element API. I managed to get my JSON file going pretty easily which was great but I've reached a point where I want to include some formatted copy as it would be output using markdown in a .twig template, is this possible?
  
  **Tags:** craft3, plugin-elementapi
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-08-21. Score: 2 | Accepted answer
  
  You can convert your Markdown text to HTML using [yii\helpers\Markdown](https://www.yiiframework.com/doc/api/2.0/yii-helpers-markdown), which is what the `|md` Twig filter hooks into:
  
  ```php
  'transformer' => function(\craft\elements\Entry $entry) {
      return [
          'body' => \yii\helpers\Markdown::process((string)$entry->yourTextFieldHandle),
      ];
  },
  
  ```
  
  If you want the equivalent of `|md('text', inlineOnly=true)` (where only inline elements are parsed – no `<p>` tags), call `processParagraph()` instead of `process()`.
  
  If you want to parse the copy as [GitHub Flavored Markdown](https://github.github.com/gfm/), pass `'gfm'` as a second argument to `process()`:
  
  ```php
  'transformer' => function(\craft\elements\Entry $entry) {
      return [
          'body' => \yii\helpers\Markdown::process((string)$entry->yourTextFieldHandle, 'gfm'),
      ];
  },
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks so much, this worked perfectly. I got something close to this but was looking for helpers within Craft. Didn't think to use Yii helpers. Thanks again!  
  
  ---
  
  