Ensure that the .md formatting is maintained when using a fresh CSS paragraph selector

I recently added a new selector in the .css file for my Hugo website to implement MLA-style indentation for references. Here is the code snippet:

.mla-ref {
    padding-left: 36px;
    text-indent: -36px;
}

Although this code creates a hanging indent as intended, it seems that the markdown formatting is not being applied correctly. For instance, when I include a title with asterisks like *Moby Dick*, it doesn't render properly.

My question is, how can I modify the .css code above to ensure that the markdown formatting for italics is preserved?

Answer №1

From Markdown to HTML

As far as I know, it's not possible to structure markdown content into semantic sections like you can with regular HTML. When you input:

# First
This is the first paragraph of the first section.

This is the second paragraph of the first section.

# Second
This is the first paragraph of the second section.

You'll just get a series of tags generated without any meaningful hierarchy.

This setup might make writing and parsing content easier, but it does pose challenges when it comes to applying custom styles selectively.

Hugo's Approach to Markdown

Hugo version 0.60+ now utilizes goldmark for handling Markdown, as detailed in the Markup Configuration docs.

Interestingly, goldmark supports custom attributes, albeit limited to headings at this point.

## heading {#id .className attrName=attrValue class="class1 class2"}

For now, you can assign a specific class like .has-mla-ref to a heading and then style its adjacent sibling accordingly.

For Example

.has-mla-ref + p {
    padding-left: 36px;
    text-indent: -36px;
}
### Reference {.has-mla-ref}

Best, David, and Sharon Marcus. “Surface Reading: An Introduction.” Representations, vol. 108, no. 1, Fall 2009, pp. 1-21. JSTOR, doi:10.1525/rep.2009.108.1.1

Moving on from references to regular content here.

Whether mere indentation suffices for MLA compliance or if more formatting is required beyond a single paragraph remains unclear. Nevertheless, this should provide some direction on how to proceed.

Answer №2

After some investigation, the solution was to design a shortcode that makes use of the paragraph style in the css:

{{- $p := .Page -}}
{{- range (split .Inner "\n") -}}
  {{- if gt (len .) 0 }}
  <p class="p2">
    {{ . | $p.RenderString }}
  </p>
  {{- end }}
{{- end -}}

For more details and the complete answer, check it out here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to dynamically set the width in CSS based on the width of characters used?

The value of rem is based on font height. Therefore, when setting width in rem for layout or media query purposes, it is determined by the height of the characters, not the width. I believe this may not be ideal for creating layouts. ...

Adjust the color of the whole row in an HTML table by changing the background

I am struggling with styling my dynamic table that pulls data from an API. I have successfully generated the table and inserted rows using JavaScript. However, I am facing styling issues. The colors of my table rows are inconsistent (similar to when using ...

Various settings in JQuery UI Slider

Does anyone know how to customize the steps in a jQuery UI slider? I want to set specific values as steps, like 0, 1200, 2000, 2200, and 3000. Any suggestions on how to achieve this? const rangeSliderInit = () => { const valueArray = [0, 400, 1000, 1 ...

Selenium was unable to find the p tag element on the webpage

I apologize for reaching out to you all for assistance with such a basic task, but I have tried everything in my toolkit and still can't seem to figure it out. I've experimented with partial xpath, full xpath, and various CSS selectors. I am see ...

Is JavaScript necessary for this task in PHP?

Hi everyone, I recently discovered a way to style a PHP echo in a more visually appealing manner. Instead of presenting an unattractive colored box right away, I was wondering if there is a way to only display the box when the user selects the calculation ...

How can I use CSS to change the background color of a fixed navbar when scrolling?

Is it possible to use only CSS to alter the background color of a fixed navbar once the user has scrolled past a specific point vertically? I am curious if this can be accomplished in CSS by targeting the ID of another element, or possibly its height? Alt ...

Height of the Accordion List

I have a code snippet below for an accordion list that I put together. I initially set the height for all the heading boxes to be uniform, but it seems like box A is displaying larger than the others. Can you help me figure out what went wrong? Any suggest ...

Varying levels of scaling on iPhone and iPad

I am currently working on a website project for my friend's brother and everything is running smoothly (for the most part). The layout of the site is designed with a centered container, leaving approximately 15-20% space from the left side. However, ...

Enhance the appearance of the circular heading

Is there anyway to customize the look of this rounded header? I am having trouble setting a white background. Update #1: This is my current header HTML code: Here is how it currently appears: I utilized Bootstrap along with some custom CSS. Update #2: ...

Attempting to align content in the center by utilizing table cells

I'm completely new to this, so please bear with me, but I have a question. I've been attempting to vertically align a div in the center of my webpage, but I can't seem to get it to work. The text always ends up loading in the top left corne ...

The MIME type 'text/html' is incompatible with stylesheet MIME type and is not supported

I have exhausted all possible solutions for the issue, from specifying the type for <link rel="stylesheet" href="./style.css" /> to using app.use(express.static('public')), but unfortunately, none of them seem to resolve the problem. index ...

Tooltips envelope around themselves

Several paragraphs contain tooltips, but some of them break onto a new line instead of staying within the text. <div class="row"> ... </div> Fiddle: https://jsfiddle.net/LhjmLw8k/29/ The issue is that certain words like "Trasimeno" and ...

Tips for positioning a label at the top of a table row in an asp.net C# application

I am facing an alignment issue in my asp.net page with a table that contains a label and a textbox. Despite trying various methods, the label consistently displays at the bottom of the row. How can I ensure that the label is aligned to either the center or ...

Ensuring the model accurately reflects the input's value attribute in AngularJS

I am in the process of creating a set of image "radio buttons" where only one can be selected per group. However, as a newcomer to Angular, I'm facing difficulties in maintaining the value and using it as my ng-model. Additionally, I am looking for a ...

Is it possible to divide a column in an HTML table into two separate

I am currently working with an array of elements that I need to iterate over. For each element, I create a <td></td> tag. When dealing with 10 elements, it results in a table with one column and 10 rows. Is there a method, using either HTML o ...

Positioning CSS icons beside text

I'm having trouble aligning a close button I created in CSS with regular text. Although the containing span element seems to align with the adjacent text, it doesn't align properly with the child divs. <a class="event-filter button" href="#"& ...

CSS - Button with upwards pointing arrow, requiring it to point downwards when hovered over

Struggling with the following issue: I have a button with a downward-pointing arrow in its description. When I hover over the button (or any content within it), I want the arrow to point upwards. However, currently, the arrow only points up when I hover ...

Maintaining the image's aspect ratio using the Next Image component

Currently, I am using Next's Image component to display a logo. Although the image itself is 1843x550 px, I have specified the width and height properties to adjust it to fit within a space of 83x24 px. However, due to a slightly different aspect rati ...

Using a `right: 0` value will not be effective when using absolute positioning

Currently, I am in the process of developing a website utilizing Bootstrap 3.3.6. After going through a tutorial on how to create a responsive banner slider, I found this resource helpful: http://www.jqueryscript.net/slider/Full-Width-Responsive-Carousel- ...

What could be causing the malfunction of the dropdown menu attached to my button?

I've been working on setting up a simple button in my Angular application that should display a dropdown menu with various options when clicked. I copied and pasted some Bootstrap template code, made some modifications to match the style of my app, bu ...