html-react-parser
Portfolio2.0
Our great sponsors
html-react-parser | Portfolio2.0 | |
---|---|---|
6 | 9 | |
1,971 | 27 | |
- | - | |
9.7 | 6.4 | |
12 days ago | 1 day ago | |
TypeScript | JavaScript | |
MIT License | GNU General Public License v3.0 or later |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
html-react-parser
-
how to inject custom js/css/html code that is fetched from an API into nextjs app?
using libraries like html-react-parser but it did not work see: https://github.com/remarkablemark/html-react-parser/discussions/1015
-
Alternatives to dangerouslySetInnerHTML
I was thinking about some sanitization library but found this: https://github.com/remarkablemark/html-react-parser which i have reviewed to deeply yet.
-
Displaying WYSIWYG editor's output with React
I'm glad I could help! Please be careful though and check the FAQ section of the library. It says that it does not sanitize and it's not XSS safe. This is the issue where they explain: https://github.com/remarkablemark/html-react-parser/issues/94
-
react-icons, custom components and JSON rendering
I then switched to html-react-parser, but same result.
-
How to Render HTML string in a React component ?
by using dangerouslySetInnerHTML, entire html in the string is preserved. Other alternative would be to use a html-react-parser library.
-
A Walkthrough of Updating My Portfolio Site with Netlify Functions and the Dev.to API
However, when I insert the body_html field into my JSX map, it's just displaying a string with a bunch html tags in it. One quick google showed me html-react-parser and after the easiest install and application, my blogs are loading beautifully with pictures and links. All I had to add was the import (import parse from 'html-react-parser';) and a couple lines to my blogList map:
Portfolio2.0
-
Dark Mode Toggle and prefers-color-scheme
You can check out all the code for this app in my portfolio repo.
-
What are Favicons?
To update my favicon, I need to update two tags in my index.html file. Because of how React works, the two paths in my href="" attributes start with %PUBLIC_URL% before the /, but here's the code with a more universal path:
-
Accessibility Auditing My Portfolio Site - Part 6
, because I want it to be visually hidden, I'll be fixing that when I get to this Github issue. WAVE mostly returned errors I had already vetted. It did actually catch one of the many broken links that I'll be fixing in this Github issue. It returned 27 long alt-text warnings on my blog page, but they're all less than 150 characters. I also got false positive contrast errors for my visually hidden skip links. ARC is down to primarily false positives. There were a couple I had to look up to make sure they were ok, like buttons with transparent backgrounds and using images with alt-text or an aria-label instead of text in links. The IBM Equal Access Accessibility checker just stopped working. It refused to scan even after I restarted Chrome, uninstalled and reinstalled it in Chrome, and installed it in Firefox. I saw something about the ruleset being undefined, so hopefully they fix that soon. Luckily, I ran it multiple times in Part 5 so I'm comfortable with moving on. The Microsoft Accessibility Insights Fast Pass didn't find anything that wasn't already on my radar, but I will be using the Assessment option as a guide for my manual testing again.
-
Accessibility Auditing My Portfolio Site - Part 4
This blog will focus on making the blog preview component code on the main page of my site more accessible.
-
An Accessible Dark Mode Toggle in React
My portfolio Github repository has all the toggle component code and the toggle CSS. The structure of the toggle looks like this:
-
Accessibility Auditing My Portfolio Site - Part 2
If I wanted these to be the most accessible, I would also add another visual cue that showed "this link will open in a new tab" on hover or focus. This would be ideal for the links attached to the Github and Chrome SVGs and for keyboard and unassisted users that don't know what the external icon link means. However, I would want to spend time I don't have today designing a nice-looking version of that, so I've added this to my Github repository as my first backlog issue for this site.
- Adding Shiba Inu Loading and Error SVGs to My React Site
-
A Walkthrough of Updating My Portfolio Site with Netlify Functions and the Dev.to API
When I found out DEV has an API that will send you the HTML of each of your blogs, I made a branch in my portfolio site repo, rewrote my FullBlog component, and attempted to call the API from within the established Blog React component. No dice. CORS error. Now I knew that I needed a server so I could use a CORS package or another solution. At this point, I also noticed I'd have to call the DEV API /articles/me endpoint to get the ids of each of my blogs and then call the /articles/{id} endpoint with the id to get the HTML version or find a solution for the markdown version.
-
Toggle Dark Mode in React
Next, I added the toggle component to my navigation bar component. I styled the toggle following Chris Bongersā Tutorial based on Katia De Juanās Dribbble. Then I adjusted the size and flipped it to default to dark mode. While this toggle is so cute that you could die, this tutorial will work with any or clickable . First, I set up the basic JSX, the local state, and a variable to hold the theme we get from localStorage: import React, { useEffect, useState } from 'react'; import '../styles/toggle.css'; import { setTheme } from '../utils/themes'; function Toggle() { const [togClass, setTogClass] = useState('dark'); let theme = localStorage.getItem('theme'); return (
{ togClass === "light" ? : }) } Enter fullscreen mode Exit fullscreen mode Finally, my favorite part: the color switching SVGs! CSS variables work in SVG code too! I got my SVG code for the Github and Chrome icons from DEVICON. For the Github icon all I had to change was one fill attribute in a : fill="var(--dark-text)"> Enter fullscreen mode Exit fullscreen mode The Chrome icon had a fill attribute in a and a : fill="var(--dark-text)" cx="63.624" cy="64.474" r="22.634"> fill="var(--dark-text)" ...> Enter fullscreen mode Exit fullscreen mode The result looks like this: Conclusion I tried to include all of the relevant code, but you can also see the full code for my site in its Github repository. If you enjoyed this article or are left with questions, please leave a comment below! I would also love to see anything built following this tutorial.
What are some alternatives?
imparse - Parser generator that can be used to quickly and succinctly define a parser definition, and to deploy an automatically-generated implementations thereof in multiple languages and on multiple platforms.
svgr - Transform SVGs into React components š¦
remarkable - Markdown parser, done right. Commonmark support, extensions, syntax plugins, high speed - all in one. Gulp and metalsmith plugins available. Used by Facebook, Docusaurus and many others! Use https://github.com/breakdance/breakdance for HTML-to-markdown conversion. Use https://github.com/jonschlinkert/markdown-toc to generate a table of contents.
wishyouwerehere - Wish You Were Here Weather App
DOMPurify - DOMPurify - a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. DOMPurify works with a secure default, but offers a lot of configurability and hooks. Demo:
BujoToGo
bbob - ā”ļøBlazing fast js bbcode parser, that transforms and parses bbcode to AST with plugin support in pure javascript, no dependencies
tdsr - A console screen reader for macOS and Linux
texthighlighter - a no dependency typescript npm package for highlighting user selected text
Font-Awesome - The iconic SVG, font, and CSS toolkit
react-icons - svg react icons of popular icon packs
heroicons - A set of free MIT-licensed high-quality SVG icons for UI development.