@richmd/react 2.0.0 → 2.0.1-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 +49 -14
- package/dist/index.es.jsx +1 -6
- package/dist/index.umd.jsx +1 -1
- package/dist/richmd.css +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -121,26 +121,61 @@ You can use the `RichmdSlide` component to create slide-style Markdown presentat
|
|
|
121
121
|
|
|
122
122
|
import { RichmdSlide } from "@richmd/react";
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
124
|
+
const md = `:use slide:
|
|
125
|
+
|
|
126
|
+
:---:title.sunset
|
|
127
|
+
# title
|
|
128
|
+
|
|
129
|
+
subtext
|
|
130
|
+
:---:
|
|
131
|
+
|
|
132
|
+
# title
|
|
133
|
+
|
|
134
|
+
:<--:content.sunset
|
|
135
|
+
# Subtitle
|
|
136
|
+
|
|
137
|
+
subtext
|
|
138
|
+
|
|
139
|
+
*subtext*
|
|
140
|
+
:---:
|
|
141
|
+
|
|
142
|
+
:<--:content.sunset
|
|
143
|
+
# List
|
|
144
|
+
|
|
145
|
+
- List
|
|
146
|
+
- List
|
|
147
|
+
- List
|
|
148
|
+
- List
|
|
149
|
+
- List
|
|
150
|
+
- List
|
|
151
|
+
:---:
|
|
134
152
|
|
|
153
|
+
:<--:content.sunset
|
|
154
|
+
# Text
|
|
155
|
+
|
|
156
|
+
===info
|
|
157
|
+
testtest
|
|
158
|
+
===
|
|
159
|
+
|
|
160
|
+
\`\`\`js
|
|
161
|
+
const a = 1;
|
|
162
|
+
console.log(a);
|
|
163
|
+
\`\`\`
|
|
164
|
+
|
|
165
|
+
$$
|
|
166
|
+
f(x) = x^2 + x + 2
|
|
167
|
+
$$
|
|
168
|
+
:---:
|
|
169
|
+
`;
|
|
170
|
+
|
|
171
|
+
export default function SlideShow() {
|
|
135
172
|
return (
|
|
136
|
-
<
|
|
137
|
-
<RichmdSlide text={markdownSlides.join("\n---\n")} isController={true} />
|
|
138
|
-
</div>
|
|
173
|
+
<RichmdSlide text={md} isController={true} />
|
|
139
174
|
);
|
|
140
175
|
}
|
|
141
176
|
```
|
|
142
177
|
|
|
143
|
-
|
|
178
|
+
Setting the `isController` property to `true` enables the slide controller.
|
|
144
179
|
|
|
145
180
|
## Component API
|
|
146
181
|
|
package/dist/index.es.jsx
CHANGED
|
@@ -347,18 +347,13 @@ const zp = (t) => {
|
|
|
347
347
|
if (S !== "\r")
|
|
348
348
|
if (S === `
|
|
349
349
|
`) {
|
|
350
|
-
if (e.length === 0 && i === gl)
|
|
351
|
-
Fp.test(a) ? (e.push(new xe.Mode("slide")), i = El, n = lr) : e.push(new xe.Mode("default"));
|
|
352
|
-
else if (n === lr && Up.test(a)) {
|
|
353
|
-
p(r);
|
|
350
|
+
if (e.length === 0 && i === gl && (Fp.test(a) ? (e.push(new xe.Mode("slide")), i = El, n = lr) : e.push(new xe.Mode("default"))), n === lr && Up.test(a)) {
|
|
354
351
|
const h = a.replace(/\:\-{3}:/, "").trim().split(".");
|
|
355
352
|
e.push(new xe.StartSlide("center", h[0], h[1] ?? "default")), n = Oe, r = "";
|
|
356
353
|
} else if (n === lr && Bp.test(a)) {
|
|
357
|
-
p(r);
|
|
358
354
|
const h = a.replace(/\:\<\-{2}:/, "").trim().split(".");
|
|
359
355
|
e.push(new xe.StartSlide("left", h[0], h[1] ?? "default")), n = Oe, r = "";
|
|
360
356
|
} else if (n === lr && Gp.test(a)) {
|
|
361
|
-
p(r);
|
|
362
357
|
const h = a.replace(/\:\-{2}\>:/, "").trim().split(".");
|
|
363
358
|
e.push(new xe.StartSlide("right", h[0], h[1] ?? "default")), n = Oe, r = "";
|
|
364
359
|
} else if (n === Oe && Yp.test(a))
|
package/dist/index.umd.jsx
CHANGED
|
@@ -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 Rr=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,ua=1,ma=2,pa=3,ga=4,Ea=5,Sa=6,ha=7,ba=8,el=9,Or=10,Ar=11,fa=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===pa?(e.push(new me.EmItalic(r)),a=rt):(e.push(new me.Text(r)),a=pa),r=""):(a===ma?(e.push(new me.Em(r)),a=rt):(e.push(new me.Text(r)),a=ma),r="");continue}a===ua?(e.push(new me.Italic(r)),a=rt):(e.push(new me.Text(r)),a=ua),r="";continue;case"_":if(t[s+1]==="_"){s+=1,t[s+1]==="_"?(s+=1,a===Sa?(e.push(new me.EmItalic(r)),a=rt):(e.push(new me.Text(r)),a=Sa),r=""):(a===Ea?(e.push(new me.Em(r)),a=rt):(e.push(new me.Text(r)),a=Ea),r="");continue}a===ga?(e.push(new me.Italic(r)),a=rt):(e.push(new me.Text(r)),a=ga),r="";continue;case"~":if(t[s+1]==="~"){s+=1,a===ha?(e.push(new me.Strikethrough(r)),a=rt):(e.push(new me.Text(r)),a=ha),r="";continue}r+=o;continue;case"`":a===Or?(e.push(new me.InlineCode(r)),a=rt):(er.isEmpty(r)||e.push(new me.Text(r)),a=Or),r="";continue;case"$":a===Ar?(e.push(new me.InlineKatex(r)),a=rt):(er.isEmpty(r)||e.push(new me.Text(r)),a=Ar),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=ba,r=o;continue;case"@":er.isEmpty(r)||e.push(new me.Text(r)),r="",a=fa,r=o;continue;case"[":if(a!==ba&&a!==fa){e.push(new me.Text(r)),a=el,r=o;continue}r+=o;continue;case")":r+=o,a===ba?(e.push(new me.Image(r)),a=rt,r=""):a===fa?(e.push(new me.Video(r)),a=rt,r=""):a===el&&(e.push(new me.Link(r)),a=rt,r="");continue;case"\\":if(a!==Or&&a!==Ar){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 ua:o="*";break;case ma:o="**";break;case pa:o="***";break;case ga:o="_";break;case Ea:o="__";break;case Sa:o="___";break;case ha:o="~~";break;case Or:o="`";break;case Ar: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,Ta=1,ol=2,sl=3,lr=4,ll=0,cl=1;let cr;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
|
|
3
|
+
`){if(e.length===0&&i===ll&&(hp.test(a)?(e.push(new Ie.Mode("slide")),i=cl,n=lr):e.push(new Ie.Mode("default"))),n===lr&&bp.test(a)){const h=a.replace(/\:\-{3}:/,"").trim().split(".");e.push(new Ie.StartSlide("center",h[0],h[1]??"default")),n=Ne,r=""}else if(n===lr&&fp.test(a)){const h=a.replace(/\:\<\-{2}:/,"").trim().split(".");e.push(new Ie.StartSlide("left",h[0],h[1]??"default")),n=Ne,r=""}else if(n===lr&&Tp.test(a)){const h=a.replace(/\:\-{2}\>:/,"").trim().split(".");e.push(new Ie.StartSlide("right",h[0],h[1]??"default")),n=Ne,r=""}else if(n===Ne&&vp.test(a))p(r),e.push(new Ie.EndSlide),n=lr,i=cl,r="";else 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?cr=h.split("."):cr=["span",""],e.push(new Ie.StartTag(cr[0]??"span",cr[1])),r=""}else if(n===Ne&&Sp.test(a))p(r),e.push(new Ie.EndTag(cr?cr[0]:"div")),r="";else if(dp.test(a))if(n===Ta)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=Ta,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
|
`:`
|