11import type { Node } from '#pm/model' ;
22import type { NodeView } from '#pm/view' ;
33
4- import { YfmCutClassName } from '../const' ;
4+ import { CutAttr , YfmCutClassName } from '../const' ;
55
66import './yfm-cut-title.scss' ;
77
@@ -17,6 +17,7 @@ export class YfmCutTitleNodeView implements NodeView {
1717 this . dom = document . createElement ( 'div' ) ;
1818 this . dom . classList . add ( YfmCutClassName . Title ) ;
1919 this . dom . addEventListener ( 'click' , this . _onTitleClick ) ;
20+ updateDomAttribute ( this . dom , CutAttr . Line , node . attrs [ CutAttr . Line ] ) ;
2021
2122 this . contentDOM = this . dom . appendChild ( document . createElement ( 'div' ) ) ;
2223 this . contentDOM . classList . add ( YfmCutClassName . TitleInner ) ;
@@ -26,6 +27,7 @@ export class YfmCutTitleNodeView implements NodeView {
2627 update ( node : Node ) : boolean {
2728 if ( this . node . type !== node . type ) return false ;
2829 this . node = node ;
30+ updateDomAttribute ( this . dom , CutAttr . Line , node . attrs [ CutAttr . Line ] ) ;
2931 return true ;
3032 }
3133
@@ -52,3 +54,11 @@ export class YfmCutTitleNodeView implements NodeView {
5254 e . preventDefault ( ) ;
5355 } ;
5456}
57+
58+ function updateDomAttribute ( elem : Element , attr : string , value : string | null | undefined ) {
59+ if ( value ) {
60+ elem . setAttribute ( attr , value ) ;
61+ } else {
62+ elem . removeAttribute ( attr ) ;
63+ }
64+ }
0 commit comments