Is there a why to process markdown content before convered into html?

I use Jekyll on Github Pages. I know nothing about ruby so I suppose I need a step by step guide on create a filter/plugin, and not sure if it works on Github…

What I want to achieve in javascript is as follows:

function spaced(str) {
	let pattern = [
		/([A-Za-z0-9\.]+\]?)([\u4e00-\u9fa5])/g,
		/([\u4e00-\u9fa5])(\[?[ A-Za-z0-9\#]+)/g
	];
	for (let i=0; i<pattern.length; i++) {
		str = str.replace(pattern[i], '$1<span class="layout-space"></span>$2');
	}
	return str;
}

Yes you’ll need to write your own plugin as a filter, in Ruby.

_plugins/spaced.rb

Custom plugins won’t run on GH Pages though unless you use a GH Actions build. See CI section of the Jekyll docs.
Or build on Netlify or similar where custom plugins are allowed and the custom build setup is easier there in my experience.

{{ value | spaced }}

Start with using a filter someone else made and get to work then customize it

What are you trying to do? Match on some unicode or emoji which has a letter before or after it and add a space between them? A literal space or <span> </span> could work out a class.

You can also see if your problem can solved using CSS only. Use the ::after or ::before selectors to add space around unicode.

Maybe you can just do a find and replace in your repo once off?

The code is for adding extra space between latin and cjk characters. I don’t want to keep these spaces in source files. I can still use javascript. But for another problem: I include a lot of line breaks in .md file and not quite willing to put trailing space or backslash to get a <br>. I don’t know if newline_to_br will work in this case…


Edit: I tried newline_to_br and it makes too many breaks…

Okay thanks.

The simplest is to run your JS using window.onload trigger and update any p tags. Jquery can help for running a transform against all matched elements

Thanks! I switch back to jQuery to solve all my problems now and will try to figure out how plugins are written.