When and how can I parse article text before posting it?

Hello,

I’d like to insert &nbsр; between a word and a preposition to it (it’s considered as the best practice in Russian). I can wrote a simple script in Ruby for that, but where and how should I call it?

You can write a custom helper.

https://middlemanapp.com/basics/helper-methods/#custom-defined-helpers

I’m not sure in what context you want to use it, Sergei, but if you want to use non-breaking space in your Middleman templates, I would just use a proper text-editor that allows that. Or you want to automate inserting it in some way? Please elaborate more.

Thank you, sir!

I like the idea, but I don’t understand 2 things:

  1. Where do I call the helper?

  2. How can I refer in the hepler to the text of the article I want to process?

Thanks for your answer!

I want to automate the inserting of non-breaking space in the places where they always should be. For example, between a preposition and the word, or between a word and m-dash after it. It will bery a very simple code, but I don’t now when or where to call it.

I still think you’ll be better off with a text-editor that preprocesses the source text (Markdown or else) for typographic niceties and such. To automate it from the other end (i.e. Middleman doing this) you would need an custom extension that does the job before handing strings over to template-processor.

Depending on what exactly you want to change and what templating language you want to use (Markdown? Haml? Just plain HTML with Ruby ERB?), this will be HTML-safe or not. It would be nice to know more details: do you want to prepare an automated way for some content-author to generate content in Markdown, without caring about those non-breaking spaces? Or you want to automate this for you, as an web-dev preparing website structure, layout, partials, generic content, using ERB, HAML etc?

I’m obsessed with typographic niceties in my web-code (non-breaking spaces where appropriate, curly-qoutes, etc.), but in case of generic website structure (HAML layout, partials) I just use the text-editor that allows me to enter this easily, and in case of the content (usually Markdown) I use preprocessing scripts of just grep Find/Replace, depending on where, for whom, etc.