@richmd/react 2.0.0-alpha.0 → 2.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -112,8 +112,40 @@ export default function MarkdownEditor() {
112
112
  }
113
113
  ```
114
114
 
115
+ ### 4. Use the RichmdSlide component (optional)
116
+
117
+ You can use the `RichmdSlide` component to create slide-style Markdown presentations. Here's an example:
118
+
119
+ ```tsx
120
+ "use client";
121
+
122
+ import { RichmdSlide } from "@richmd/react";
123
+
124
+ export default function SlideShow() {
125
+ const markdownSlides = [
126
+ `# Slide 1
127
+ Welcome to **RichmdSlide**!`,
128
+ `# Slide 2
129
+ - Create slides easily
130
+ - Supports Markdown syntax`,
131
+ `# Slide 3
132
+ > "Markdown made interactive!"`,
133
+ ];
134
+
135
+ return (
136
+ <div className="slideshow-container">
137
+ <RichmdSlide text={markdownSlides.join("\n---\n")} isController={true} />
138
+ </div>
139
+ );
140
+ }
141
+ ```
142
+
143
+ In this example, `---` is used to separate slides. Setting the `isController` property to `true` enables the slide controller.
144
+
115
145
  ## Component API
116
146
 
147
+ ### `Richmd`
148
+
117
149
  The `Richmd` component accepts the following props:
118
150
 
119
151
  | Prop | Type | Required | Description |
@@ -122,6 +154,16 @@ The `Richmd` component accepts the following props:
122
154
  | `id` | string | No | HTML id attribute for the container div |
123
155
  | `className` | string | No | CSS class name for the container div |
124
156
 
157
+
158
+ ### `RichmdSlide`
159
+
160
+ The `RichmdSlide` component accepts the following props:
161
+
162
+ | Prop | Type | Required | Description |
163
+ |------|------|----------|-------------|
164
+ | `text` | string | Yes | The markdown text to render |
165
+ | `isController` | boolean | Yes | Toggles the display of the slide controller |
166
+
125
167
  ## Supported Markdown Features
126
168
 
127
169
  Richmd supports a wide range of markdown features:
@@ -141,7 +183,8 @@ Richmd supports a wide range of markdown features:
141
183
  - Video (HTML5 video tag)
142
184
  - Custom HTML tags
143
185
 
144
- For detailed syntax documentation, refer to the [Richmd Markdown Syntax Documentation](https://github.com/richmd/core/blob/main/docs/md-syntax.md).
186
+ For detailed syntax documentation, refer to the [Richmd Markdown Syntax Documentation](./docs/md-syntax.md).
187
+
145
188
 
146
189
  ## License
147
190
 
package/dist/index.es.jsx CHANGED
@@ -353,15 +353,15 @@ const zp = (t) => {
353
353
  if (Up.test(a)) {
354
354
  p(r);
355
355
  const h = a.replace(/\:\-{3}:/, "").trim().split(".");
356
- e.push(new xe.StartSlide("center", h[0], h[1])), n = Oe;
356
+ e.push(new xe.StartSlide("center", h[0], h[1] ?? "default")), n = Oe;
357
357
  } else if (Bp.test(a)) {
358
358
  p(r);
359
359
  const h = a.replace(/\:\<\-{2}:/, "").trim().split(".");
360
- e.push(new xe.StartSlide("left", h[0], h[1])), n = Oe;
360
+ e.push(new xe.StartSlide("left", h[0], h[1] ?? "default")), n = Oe;
361
361
  } else if (Gp.test(a)) {
362
362
  p(r);
363
363
  const h = a.replace(/\:\-{2}\>:/, "").trim().split(".");
364
- e.push(new xe.StartSlide("right", h[0], h[1])), n = Oe;
364
+ e.push(new xe.StartSlide("right", h[0], h[1] ?? "default")), n = Oe;
365
365
  } else Yp.test(a) && (p(r), e.push(new xe.EndSlide()), n = Ma);
366
366
  (n === Ma || n === Oe) && (r = "");
367
367
  }
@@ -1,6 +1,6 @@
1
1
  (function(Et,Be){typeof exports=="object"&&typeof module<"u"?Be(exports,require("react"),require("html-react-parser")):typeof define=="function"&&define.amd?define(["exports","react","html-react-parser"],Be):(Et=typeof globalThis<"u"?globalThis:Et||self,Be((Et.richmd=Et.richmd||{},Et.richmd.react={}),Et.React,Et.parse))})(this,function(Et,Be,Js){"use strict";function Rm(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,a.get?a:{enumerable:!0,get:()=>t[r]})}}return e.default=t,Object.freeze(e)}const Nr=Rm(Be);class ue{constructor(e,r){this.name=e,this.type=r}}const Om=/^!\[([^\]]*)?\]\(([^\)]+)\)$/,Am=/^@\[([^\]]*)?\]\(([^\)]+)\)$/,Im=/^\[([^\]]*)?\]\(([^\)]+)\)$/;class xm extends ue{constructor(e){super("text","inline"),this.value=e}}class Dm extends ue{constructor(e){super("html","inline"),this.value=e}}class wm extends ue{constructor(e){super("htmlcomment","inline"),this.value=e}}class Mm extends ue{constructor(e){super("em","inline"),this.value=e}}class Lm extends ue{constructor(e){super("italic","inline"),this.value=e}}class km extends ue{constructor(e){super("emitalic","inline"),this.value=e}}class Pm extends ue{constructor(e){super("strikethrough","inline"),this.value=e}}class Fm extends ue{constructor(e){super("code","inline"),this.value=e}}class Um extends ue{constructor(e){const r=e.match(Om);super("image","inline"),r?(this.alt=r[1]||"",this.src=r[2]||""):(this.alt="",this.src="")}}class Bm extends ue{constructor(e){const r=e.match(Am);super("video","inline"),r?this.src=r[2]||"":this.src=""}}class Gm extends ue{constructor(e){const r=e.match(Im);super("link","inline"),r?(this.title=r[1]||"",this.href=r[2]||""):(this.title="",this.href="")}}class Ym extends ue{constructor(e){super("katex","inline"),this.value=e}}const me={Text:xm,Html:Dm,HtmlComment:wm,Em:Mm,Italic:Lm,EmItalic:km,Strikethrough:Pm,InlineCode:Fm,Image:Um,Video:Bm,Link:Gm,InlineKatex:Ym},zm=/^\s*$/,Hm=t=>t.length===0||zm.test(t),er={isEmpty:Hm},rt=0,_a=1,ua=2,ma=3,pa=4,ga=5,Ea=6,Sa=7,ha=8,el=9,Rr=10,Or=11,ba=12,zt=t=>{const e=[];let r="",a=rt,n=!1;const i=[];for(let s=0;s<t.length;s+=1){const o=t[s];if(n===!0){r+=o,n=!1;continue}switch(o){case"*":if(t[s+1]==="*"){s+=1,t[s+1]==="*"?(s+=1,a===ma?(e.push(new me.EmItalic(r)),a=rt):(e.push(new me.Text(r)),a=ma),r=""):(a===ua?(e.push(new me.Em(r)),a=rt):(e.push(new me.Text(r)),a=ua),r="");continue}a===_a?(e.push(new me.Italic(r)),a=rt):(e.push(new me.Text(r)),a=_a),r="";continue;case"_":if(t[s+1]==="_"){s+=1,t[s+1]==="_"?(s+=1,a===Ea?(e.push(new me.EmItalic(r)),a=rt):(e.push(new me.Text(r)),a=Ea),r=""):(a===ga?(e.push(new me.Em(r)),a=rt):(e.push(new me.Text(r)),a=ga),r="");continue}a===pa?(e.push(new me.Italic(r)),a=rt):(e.push(new me.Text(r)),a=pa),r="";continue;case"~":if(t[s+1]==="~"){s+=1,a===Sa?(e.push(new me.Strikethrough(r)),a=rt):(e.push(new me.Text(r)),a=Sa),r="";continue}r+=o;continue;case"`":a===Rr?(e.push(new me.InlineCode(r)),a=rt):(er.isEmpty(r)||e.push(new me.Text(r)),a=Rr),r="";continue;case"$":a===Or?(e.push(new me.InlineKatex(r)),a=rt):(er.isEmpty(r)||e.push(new me.Text(r)),a=Or),r="";continue;case"<":{er.isEmpty(r)||(i.length===0?e.push(new me.Text(r)):i[i.length-1]+=r,r="");let c=o;if(c!=="<"){do r+=c,c=t[s+=1];while(c!==">");r+=c}else r+=c;if(r[1]==="/"){const _=i.pop()+r;e.push(new me.Html(_))}else r[1]==="!"?e.push(new me.HtmlComment(r)):r==="<"?e.push(new me.Text(r)):i.push(r);r="";continue}case"!":er.isEmpty(r)||e.push(new me.Text(r)),r="",a=ha,r=o;continue;case"@":er.isEmpty(r)||e.push(new me.Text(r)),r="",a=ba,r=o;continue;case"[":if(a!==ha&&a!==ba){e.push(new me.Text(r)),a=el,r=o;continue}r+=o;continue;case")":r+=o,a===ha?(e.push(new me.Image(r)),a=rt,r=""):a===ba?(e.push(new me.Video(r)),a=rt,r=""):a===el&&(e.push(new me.Link(r)),a=rt,r="");continue;case"\\":if(a!==Rr&&a!==Or){n=!0;continue}break;default:r+=o;break}}if(!er.isEmpty(r)){const s=e[e.length-1];if(!s||a===rt)e.push(new me.Text(r));else{let o="";switch(a){case _a:o="*";break;case ua:o="**";break;case ma:o="***";break;case pa:o="_";break;case ga:o="__";break;case Ea:o="___";break;case Sa:o="~~";break;case Rr:o="`";break;case Or:o="$";break}s.value+=`${o}${r}`}}return e};class qm extends ue{constructor(e){super("mode","block"),this.mode=e}}class Vm extends ue{constructor(e){super("paragraph","block"),this.values=zt(e)}}class $m extends ue{constructor(){super("horizontal","block")}}class Wm extends ue{constructor(){super("br","block")}}class Qm extends ue{constructor(e,r,a){super("code","block"),this.syntax=r,this.file=a,this.values=[new me.Text(e)]}}class Km extends ue{constructor(e){super("katex","block"),this.values=[new me.Text(e)]}}class jm extends ue{constructor(e,r){super("color","block"),this.style=r,this.values=zt(e)}}class Xm extends ue{constructor(e,r){super("blockquote","block"),this.level=r,this.values=zt(e)}}class Zm extends ue{constructor(e,r){if(r===0||r>6)throw new Error("Invalid heading: heading support only between H1 and H6");super("heading","block"),this.level=r,this.values=zt(e)}}class Jm extends ue{constructor(e,r){super("list","block"),this.level=r,this.values=zt(e)}}class ep extends ue{constructor(e,r,a){super("orderedlist","block"),this.level=a,this.order=r,this.values=zt(e)}}class tp extends ue{constructor(e,r,a){super("checklist","block"),this.level=a,this.checked=r,this.values=zt(e)}}class rp extends ue{constructor(e){super("table","block"),this.headings=[],this.aligns=[],this.rows=[];const[r,a,...n]=e.map(i=>i.replace(/^\||\|$/g,"").split("|"));r!==void 0&&(this.headings=r.map(i=>i.trim())),a!==void 0&&(this.aligns=a.map(i=>{const s=i.trim();let o="left";return s[s.length-1]===":"&&(o=s[0]===":"?"center":"right"),o})),n!==void 0&&(this.rows=n.map(i=>i.map(s=>zt(s.trim()))))}}class ap extends ue{constructor(e){super("startDetails","block"),this.summary=e}}class np extends ue{constructor(){super("endDetails","block")}}class ip extends ue{constructor(e,r){super("startTag","block"),this.style=r,this.tag=e}}class op extends ue{constructor(e){super("endTag","block"),this.tag=e}}class sp extends ue{constructor(e,r,a){super("startSlide","block"),this.layout=e,this.mode=r,this.theme=a}}class lp extends ue{constructor(){super("endSlide","block")}}const Ie={Paragraph:Vm,Horizontal:$m,Code:Qm,Katex:Km,ColorBlock:jm,Blockquote:Xm,Heading:Zm,List:Jm,CheckList:tp,OrderedList:ep,Table:rp,Br:Wm,StartDetails:ap,EndDetails:np,StartTag:ip,EndTag:op,StartSlide:sp,EndSlide:lp,Mode:qm},tl=/^(#{1,})\s(.+)$/,rl=/^(\s*)?(?:\-|\*)\s(.+)$/,al=/^(\s*)?([0-9]+)\.\s(.+)$/,cp=/^[\*\-_\s]+$/,dp=/^[`~]{3}(.*)|[`~]{3}(.*)\b[\l]+\b\:\b[\u\l]+\b$/,nl=/^(>{1,})\s?(.+)$/,il=/(?:\s*)?\|(.+)\|(?:\s*)$/,_p=/^[\$]{2}(.*)$/,up=/^[\$]{2}\s(.+)\s[\$]{2}$/,mp=/^[\=]{3}(.*)|[\=]{3}(.*)\b[\l]+\b$/,pp=/^\:\>(\b[\w_\.\/]+\b|[\u3040-\u309F\u30A0-\u30FF\u3400-\u9FFF])+$/,gp=/^\:\>$/,Ep=/^\:\:\b[a-z]+\b|\:\:\b[a-z]+\b\.\b[a-z]+\b|\:\:\.\b[a-z]+\b$/,Sp=/^\:\:$/,hp=/^\:use\sslide\:$/,bp=/^\:\-{3}\:(title|content)|\:\-{3}\:(title|content)\.\b[a-z]+\b$/,fp=/^\:\<\-{2}\:(title|content)|\:\<\-{2}\:(title|content)\.\b[a-z]+\b$/,Tp=/^\:\-{2}\>\:(title|content)|\:\-{2}\>\:(title|content)\.\b[a-z]+\b$/,vp=/^\:\-{3}\:$/,Ne=0,fa=1,ol=2,sl=3,Ta=4,ll=0,cl=1;let lr;const Cp=t=>{const e=[];t&&!/\n$/.test(t)&&(t+=`
2
2
  `);let r="",a="",n=Ne,i=ll,s=[],o,c="",_="",u="default";const p=E=>{s.length>0&&(e.push(new Ie.Table(s)),s=[]),er.isEmpty(E)||e.push(new Ie.Paragraph(E))};for(let E=0;E<t.length;E+=1){const S=t[E];if(S!=="\r")if(S===`
3
- `){if(e.length===0&&i===ll)hp.test(a)?(e.push(new Ie.Mode("slide")),i=cl,n=Ta):e.push(new Ie.Mode("default"));else if(i===cl){if(bp.test(a)){p(r);const h=a.replace(/\:\-{3}:/,"").trim().split(".");e.push(new Ie.StartSlide("center",h[0],h[1])),n=Ne}else if(fp.test(a)){p(r);const h=a.replace(/\:\<\-{2}:/,"").trim().split(".");e.push(new Ie.StartSlide("left",h[0],h[1])),n=Ne}else if(Tp.test(a)){p(r);const h=a.replace(/\:\-{2}\>:/,"").trim().split(".");e.push(new Ie.StartSlide("right",h[0],h[1])),n=Ne}else vp.test(a)&&(p(r),e.push(new Ie.EndSlide),n=Ta);(n===Ta||n===Ne)&&(r="")}if(n===Ne&&pp.test(a)){p(r);const h=a.replace(/\:\>/,"").trim();e.push(new Ie.StartDetails(h)),r=""}else if(n===Ne&&gp.test(a))p(r),e.push(new Ie.EndDetails),r="";else if(n===Ne&&Ep.test(a)){p(r);const h=a.replace(/\:\:/,"").trim();h?lr=h.split("."):lr=["span",""],e.push(new Ie.StartTag(lr[0]??"span",lr[1])),r=""}else if(n===Ne&&Sp.test(a))p(r),e.push(new Ie.EndTag(lr?lr[0]:"div")),r="";else if(dp.test(a))if(n===fa)e.push(new Ie.Code(r.trim(),c,_)),c="",_="",n=Ne,r="";else if(n===Ne){p(r);const h=a.replace(/\`\`\`/,"").trim().split(":");c=h[0],_=h[1],n=fa,r=""}else r+=a!==""?`${a}
3
+ `){if(e.length===0&&i===ll)hp.test(a)?(e.push(new Ie.Mode("slide")),i=cl,n=Ta):e.push(new Ie.Mode("default"));else if(i===cl){if(bp.test(a)){p(r);const h=a.replace(/\:\-{3}:/,"").trim().split(".");e.push(new Ie.StartSlide("center",h[0],h[1]??"default")),n=Ne}else if(fp.test(a)){p(r);const h=a.replace(/\:\<\-{2}:/,"").trim().split(".");e.push(new Ie.StartSlide("left",h[0],h[1]??"default")),n=Ne}else if(Tp.test(a)){p(r);const h=a.replace(/\:\-{2}\>:/,"").trim().split(".");e.push(new Ie.StartSlide("right",h[0],h[1]??"default")),n=Ne}else vp.test(a)&&(p(r),e.push(new Ie.EndSlide),n=Ta);(n===Ta||n===Ne)&&(r="")}if(n===Ne&&pp.test(a)){p(r);const h=a.replace(/\:\>/,"").trim();e.push(new Ie.StartDetails(h)),r=""}else if(n===Ne&&gp.test(a))p(r),e.push(new Ie.EndDetails),r="";else if(n===Ne&&Ep.test(a)){p(r);const h=a.replace(/\:\:/,"").trim();h?lr=h.split("."):lr=["span",""],e.push(new Ie.StartTag(lr[0]??"span",lr[1])),r=""}else if(n===Ne&&Sp.test(a))p(r),e.push(new Ie.EndTag(lr?lr[0]:"div")),r="";else if(dp.test(a))if(n===fa)e.push(new Ie.Code(r.trim(),c,_)),c="",_="",n=Ne,r="";else if(n===Ne){p(r);const h=a.replace(/\`\`\`/,"").trim().split(":");c=h[0],_=h[1],n=fa,r=""}else r+=a!==""?`${a}
4
4
  `:`
5
5
  `;else if(n===Ne&&up.test(a)){p(r),r="";const h=a.replace(/\$\$/g,"").trim();e.push(new Ie.Katex(h))}else if(_p.test(a))n===ol?(e.push(new Ie.Katex(r.trim())),n=Ne,r=""):n===Ne?(p(r),n=ol,r=""):r+=a!==""?`${a}
6
6
  `:`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@richmd/react",
3
- "version": "2.0.0-alpha.0",
3
+ "version": "2.0.0-rc.0",
4
4
  "description": "It is a react package of Richmd.",
5
5
  "exports": {
6
6
  ".": {
@@ -41,7 +41,7 @@
41
41
  "license": "MIT",
42
42
  "dependencies": {
43
43
  "@react-hook/event": "^1.2.6",
44
- "@richmd/js": "2.0.0-alpha.0",
44
+ "@richmd/js": "2.0.0",
45
45
  "html-react-parser": "^5.2.2",
46
46
  "react": "^19.0.0",
47
47
  "react-dom": "^19.0.0"