Squarespace Markdown



Markdown Text Block Resources you may find helpful: Squarespace’s ‘Using Markdown Text Blocks’ Squarespace’s ‘Markdown Cheat Sheet’ Markdown Cheat Sheet by Adam Pritchard. And W3Schools.com is a wonderful resource for learning how to customize anything and everything on your website by learning CSS & HTML coding + more! App Squarespace Edit a page or post, click an insert point, and select Markdown from the menu. For help, visit Adding content with blocks. Add Markdown text in the Markdown box.

Here's a concise solution for creating hide/show text in Squarespace pages, using a Markdown Block and a jQuery script.

The code on this page is free for you to install on your Squarespace site.

+ How does it work?

The solution uses a Markdown block to hold the questions and answers. For this version of the script it should be the only Markdown block on the page, though I may improve the script at a later date to allow for multiple open/close areas.

A jQuery script then manipulates the Markdown block to add the open/close behaviour.

+ Why Markdown?

The native Squarespace html layouts can be difficult to interpret. Placing a single Markdown block on a page makes it very easy to target with scripting as it has a class of .markdown-block.

Markdown is also easier for a non technical user to edit or add content compared to raw html.

  • It supports bullet points and otherstylingcodes

Markdown blocks can also include html, which opens up the possibility for richer experiences that include imagery and other embedded media.

Squarespace Markdown Center Text

+ Why jQuery

jQuery is a Javascript framework that removes a lot of complexity when coding solutions that need to work on multiple web browsers.

This open/close functionality is expressed in 4 lines of jQuery code (excluding the call to the main jQuery library) whereas a pure Javascript solution would be far longer.

It's true that the jQuery library can add page load time, but in my code I link to the one hosted on Google's content delivery network, which means there's a strong chance that a user already has the jQuery library in their browser cache.

The solution

NB. Code samples may be reused subject to certain conditions.

Squarespace Markdown

The Markdown

What Is A Squarespace Markdown

IMPORTANT: The content of the FAQ Questions & Answers MUST be inserted into a Markdown Block. Using a standard text block or code block won't work.

Here's the Markdown code that drives the example at the top of this page. I've edited out a lot of the content to make is easier to read.

  • ## Denotes an H2 heading. The script interprets these as the links that open/close the content sections.
  • The + sign is used as a signifier that the heading can be opened.

The jQuery code

You need the following code call in either your sitewide code injection point or on the page's code injection point. If you already using jQuery scripts elsewhere on your site you can omit this line.

Next up we have the code that does all of the work.

First off there's a clean version for copying and pasting into your page's code injection point. After that I've included an annotated version so that you can understand what's going on.

Clean version:

Variation 1 - Making displayed answer retract when a new FAQ is clicked:

Variation 2 - Toggling the + / - symbols

Font Size In Markdown

First, the script: