Tips for showcasing HTML code in Highlights.js

I am currently working on a project showcased in this demo. I am facing an issue with the rendering of HTML markup in the snippet highlighter library called highlights.js. Can anyone help me figure out why this is happening?

<pre><code class="html">
 <a role="button" class="btn btn-default btn-block">Item 4</a>
</code></pre>

$(document).ready(function() {
  $('pre code').each(function(i, e) {hljs.highlightBlock(e)});
});

Answer №1

Your code is correct, but it seems like there are some characters that were escaped or not translated correctly on Fiddle. Following Mike's suggestion, you need to escape the HTML:

<pre><code class="html">
  &lt;a role="button" class="btn btn-default btn-block"&gt;Item 4&lt;/a&gt;
</code></pre>

Check out this link for a working example: http://jsfiddle.net/ng4tkw5j/2/

Alternatively, I tried using another language like PHP and it worked fine: http://jsfiddle.net/x3NXY/

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

Issue with Bootstrap 4 nested tabs retaining active status

I'm having some issues with my nested tabs, both vertical and horizontal, as they are not switching the active states properly and some bugs are arising. body { min-height: 100%; } <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/b ...

My regex match isn't functioning as expected when using jQuery's textcomplete feature

I have implemented a jQuery plugin(part 3) from this website to provide autocomplete functionality for text input. The current regex used for matching is: match: /\B@(\w*)$/, However, I am facing an issue where I want the autocomplete options to ...

Issue with Jquery - Variable not getting updated on resize event, causing multiple saves

After creating this jQuery script to enable/disable a fixed position div based on user scrolling behavior, I encountered an issue where the functionality breaks upon window resizing. Despite my attempts to update the variables correctly after resizing, the ...

Can a component be added with the press of a button?

Let's tackle this challenge together: I have a button that, when clicked, should add my-component to the DOM. If the button is pressed twice, there should be two <p> tags appended. How can I make this happen? JS: <script> Vue.compone ...

What is the best way to render geoJSON as a mesh instead of a line in three.js, and apply a color fill to it?

Currently working on a three.js globe project that involves adding data layers using geoJSON. The initial layer, representing countries, is displayed as lines thanks to ThreeGeoJSON. https://i.sstatic.net/nuBkR.png However, I am aiming to go beyond just ...

"Delving into the intricacies of Angular's factory

If I have a factory like the one below: app.factory("categoryFactory", function (api, $http, $q) { var selected = null; var categoryList = []; return { getList: function () { var d = $q.defer(); if(categoryL ...

Clicking on the menu in mobile view will cause it to slide upward

I have implemented sticky.js on my website and it is working well. However, when I resize the browser to mobile view and click the main menu button, it goes up and I am unable to close it. I have to scroll up to see it again. How can I make it stick to the ...

Sharing context sub files in Next.js can be easily accomplished by following a few simple

These are the pages on my website: /pages /gift /[slug] index.tsx /personalize index.tsx In /gift/[slug]/index.tsx, I have a component called GiftProvider that looks like this: return ( <GiftProvider gift={gift}& ...

Determine the selected radio button

----EDIT---- I am developing a jQuery mobile application and I need to determine which radio button is selected. This is the JavaScript code I'm using: function filter(){ if(document.getElementById('segment1').checked) { aler ...

Guide to refining a JSON array using a pre-established list

I'm in need of assistance figuring out how to accomplish the following task: Below is the code snippet I am working with: public class Data { public string FirstName; public string LastName; public int Age; } var data = new Data { //this objec ...

Ways to create an object based on another object

Currently, I am teaching myself Javascript. My focus is on working with Vuejs and express for a CRUD App. In one of my components, I retrieve data from my backend using the API: localhost:3000/api/transport. The response contains all objects from the data ...

Passing dynamic props to Vue mixin: a guide

Can we pass dynamic props to a Vue mixin from its parent component? Here's the scenario. This mixin is set up to receive an isActive prop. mixin.ts export default { props: { isActive: { type: Boolean, required: true } }, wa ...

The server node proxy is failing to trigger the API call

update 1: After modifying the api path, I am now able to initiate the api call. However, I encountered the following error: (node:13480) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): RangeError: Invalid status code: res ...

What could be causing my webpage to automatically refresh following a POST request in NodeJS?

Utilizing the express framework alongside NodeJS, I have encountered an issue where my client webpage refreshes after making a POST request that triggers a python script and returns a JSON object to the client. My dilemma lies in preventing this automatic ...

Guide on how to retrieve the parent element's number when dragging starts

Within my div-containers, I have a collection of div-elements. I am looking to identify the parent number of the div-element that is currently being dragged For example, if Skyler White is being dragged, the expected output should be "0" as it is from the ...

How to retrieve an array value within a function in AngularJS

<select class="form-control" id="column" ng-model="selectedcolumn" ng-options="column for column in columns"></select> <input type="text" ng-model="test[selectedcolumn]" ng-change="search()" /> Is there a way to retrieve the value o ...

What is the reason for `change()` not being defined in the constructor? Is it supposed to be accessed through the `__proto__` link in `

Why is the change() method not defined in the constructor? Shouldn't it be accessed through the proto link in the p.proto? // The first change() is not defined, why? class Person { constructor() { console.log(this) console.log(this.__prot ...

Trouble with triggering events from Datatable buttons

Below is the code snippet I am currently using for my DataTable : var oTable12= $('#example').DataTable({ "aaData": tableData, "aLengthMenu": [[5, 10, 20, -1], [5, 10, 20, "All"]], "iDisplayLength": 5, "aoColumnDefs ...

Python code allowing users to navigate back to the previous page while retaining elements

After my script scrapes the page, it automatically clicks a button if a new element meeting certain criteria is found. Everything works perfectly when there is only one element, but an issue arises when the button click leads to a new page opening. If ther ...

How can I create a real-time page update using node.js?

I am completely new to node.js, but my main goal in learning this language is to achieve a specific task. I want to create a webpage where the content within a designated "div" can be swapped dynamically for users currently viewing the page. For example, ...