Jump to content
Ryan Pierce

Inline Images and Markdown

Recommended Posts

Is there a way to use the ProcessWire API to insert images into the text of a Markdown field?

Something kind of like this:

<?php $image1 = $page->image->url; ?>

![This is my image](<?=image1?>)

The end goal here is to be able to write posts in a Markdown-like way but have ProcessWire handle all of the image paths and ordering.

Share this post


Link to post
Share on other sites

It isn't, not with 'vanilla' PW.

But there are already some modules that can give you this – search http://modules.processwire.com/ and it's pretty simple to roll your own.

In case you want to build micromodule for yourself, to learn a little, do following:

- create textformatter module – you'll add it to the textarea (before md parsing!)

- comeup with some combination of letters not naturaly used in text

- capture the text

- find correct picture for it

- replace the original text with pictures URL

done. When I did this last time (can't share code due to licensing issues, but it was fun to build it nevertheless), it took something like 20-30 lines to do it (excluding PW's module structure), so… pretty simple. :)

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By DooM
      Hey guys,
      I'm using Form builder module by Ryan and I'm trying to render HTML success message after form is sent using value from this field:

      but it renders exactly as it is written in the field, not as HTML. To render it I just use echo
      <?= $successMessage ?> What am I missing?
       
      Thanks for any help. 🧒
    • By clsource
      Hello, A friend posted a question about how obtain the markdown code for a image when you are using the markdown editor.
      Here I created a module just for that.

       


      You can download it here.
       
      https://github.com/NinjasCL/InputfieldImageMarkdownCodeAdditionalFields
       
      cheers.

    • By Robin S
      A proof-of-concept module.
      ImageToMarkdown
      Alt+click an image in Page Edit to copy an image markdown string to clipboard.
      Usage
      Install the ImageToMarkdown module.
      Alt+click an image in Page Edit to copy an image markdown string to clipboard. If the "Description" field is populated it is used as the alt text.

       
      https://github.com/Toutouwai/ImageToMarkdown
    • By gerritvanaaken
      I’m using the core-embedded TextformatterMarkdownExtra module, but I do not like the autolinking of URLs. Can it be turned off somehow, or do I have to install a custom Textformatter plugin which has this option turned off?
    • By phil_s
      While looking for a way to add target="_blank" to markdown formatted fields I came across these little gems in the TextformatterMarkdownExtra.module (in the wire>modules>textformatter folder, I'm running v3.0.33). Turns out someone (Ryan? Did you add this?) already thought of it:
      /** * A couple RCD extentions to MarkDown syntax, to be executed after Markdown has already had it's way with the text */ protected function markdownExtensions(&$str) { // add id attribute to a tag, when followed by a #myid if(strpos($str, '>#')) $str = preg_replace('/<([a-z][a-z0-9]*)([^>]*>.*?)(<\/\\1>)#([a-z][-_a-z0-9]*)\b/', '<$1 id="$4"$2$3', $str); // add class attribute to tag when followed by a .myclass if(strpos($str, '>.')) $str = preg_replace('/<([a-z][a-z0-9]*)([^>]*>.*?)(<\/\\1>)\.([a-z][-_a-z0-9]*)\b/', '<$1 class="$4"$2$3', $str); // href links open in new window when followed by a plus sign, i.e. [google](http://google.com)+ if(strpos($str, '</a>+')) $str = preg_replace('/<a ([^>]+>.+?<\/a>)\+/', '<a target="_blank" $1', $str); // strip out comments // if(strpos($text, '/*') !== false) $text = preg_replace('{/\*.*?\*/}s', '', $text); // if(strpos($text, '//') !== false) $text = preg_replace('{^//.*$}m', '', $text); }  
      Adding:
      $f->addOption(self::flavorRCD, 'RCD extentions'); after line 107 of the file, adds an option field which you can handily check from the module's config screen in the admin. Now, the question I should have asked before doing this is:
      Does changing that have any detrimental effect on things I don't know about yet? : )
      Would be great if someone with actual knowledge on this could chime in before I shoot myself in the foot (There must be a reason why this is not active by default?)
      Cheers guys!
      Phil
       
×
×
  • Create New...