Skip to content

{ Category Archives } PHP

A programmable color scheme

I'm not a designer, and I've never been happy with the color scheme for kavanot.name, so I decided to try something new. I use scssphp with scssphp server (and yes, you need both) to generate the CSS, and it allows variables, so I can do: $hue = 250; $saturation = '40%'; $textcolor: hsl($hue, $saturation, 10%); […]

Extending Parsedown: attributes

Markdown Extra (including Parsedown Extra) allows for attributes to be applied to certain elements: headers, fenced code blocks, links, and images. I'd like to be able to apply them to any element. I'm going to use the syntax of Python Markdown attributes, but the attribute lists go before the elements. For block level elements, they […]

Extending Parsedown: Block elements

Continuing work on extending Parsedown. See the actual code. Adding block-level elements is not much different from adding inline elements. Kavanot.name originally used <footer> elements to indicate the source of a block quote: <blockquote> Do or do not. There is no try. </blockquote> <footer>Yoda</footer> </blockquote> While marking blockquotes this way is now acceptable, for a […]

Extending Parsedown: Inline elements

Extending Parsedown involves adding elements to the $InlineTypes and $BlockTypes arrays, then adding methods to handle them. See the actual code. Italics I use <i> a lot, to indicate transliterated words. So I use could use "/" to indicate that: /Shabbat/ is a Hebrew word becomes <i>Shabbat</i> is a Hebrew word. To do that: do […]

String Replacement in PHP

Working with Parsedown, I want to string manipulation but only in certain parts. For instance, on text not in HTML tags or not in quotes. The right way to do that is with a real parser. The easy way is by removing the unwanted strings, replacing them with a marker that won't come up in […]

Extending Parsedown

I've been spending all my intellectual free time on working on my Kavanot site, so I haven't been doing any independent programming. But that site uses raw HTML, which is a pain to type. So I decided to start using Markdown to make writing easier. After a little trial and error, I decided to use […]

‘ob_gzhandler’ conflicts with ‘zlib output compression’

Nearly Free Speech has been a great hosting service, and they upgrade the stack consistently, which usually doesn't cause problems. But with the most recent upgrade, I started getting the above error. Looks like they turned on compression at the server level, so doing it on each page is redundant. Evidently they announced it on […]

Custom Buttons in the WordPress HTML Editor

I use the WordPress HTML editor exclusively, with the Text Control plugin with no formatting, so the posts contain exactly the markup I want. The editor comes with "Quick Tag" buttons, that let you insert HTML tags with one click, and allows you to add custom buttons. So, for all my code samples, I want […]

Contextual Search Results in WordPress

Michael Tyson had a cool idea: instead of the search results page showing an excerpt of the first words of the post, show an excerpt that contains the search terms and highlight them (say, by making them bold). I thought his method was too complex—it requires replacing your theme's search.php with a custom page, and […]

Replace Text not in Tags

I wanted a way to highlight search terms on the search results page (the way search engines do), by surrounding the text with <span class=whatever></span>, but simply doing preg_replace($re, '<span class=whatever>$0</span>', $text) replaces things inside any HTML tags as well. There are some solutions on the web, but the simplest one I found involves generating […]