@@ -289,7 +289,7 @@ struct BuilderContext {
289289};
290290
291291static void _buildNode (BuilderContext bc, Gc::Ref<Dom::Node> node);
292- static void _buildPseudoElement (BuilderContext bc, Rc<Dom::PseudoElement> pseudoElement);
292+ static void _buildPseudoElement (BuilderContext bc, Gc::Ref<Dom::Element> originatingElement, Rc<Dom::PseudoElement> pseudoElement);
293293
294294// MARK: Build void/leaves ---------------------------------------------------------
295295
@@ -720,7 +720,7 @@ static void _buildTableBox(BuilderContext tableWrapperBc, Gc::Ref<Dom::Element>
720720 }
721721
722722 if (auto before = el->getPseudoElement (Dom::PseudoElement::BEFORE )) {
723- _buildPseudoElement (tableWrapperBc, before.unwrap ());
723+ _buildPseudoElement (tableWrapperBc, el, before.unwrap ());
724724 }
725725
726726 // An anonymous table-row box must be generated around each sequence of consecutive children of a table-root
@@ -735,7 +735,7 @@ static void _buildTableBox(BuilderContext tableWrapperBc, Gc::Ref<Dom::Element>
735735 }
736736
737737 if (auto before = el->getPseudoElement (Dom::PseudoElement::AFTER )) {
738- _buildPseudoElement (tableWrapperBc, before.unwrap ());
738+ _buildPseudoElement (tableWrapperBc, el, before.unwrap ());
739739 }
740740}
741741
@@ -802,16 +802,22 @@ static void _innerDisplayDispatchCreationOfInlineLevelBox(BuilderContext bc, Gc:
802802
803803static void _buildChildren (BuilderContext bc, Gc::Ref<Dom::Node> parent) {
804804 auto el = parent->is <Dom::Element>();
805+ if (el->specifiedValues ()->display == Display::Item::YES ) {
806+ if (auto marker = el ? el->getPseudoElement (Dom::PseudoElement::MARKER ) : NONE ) {
807+ _buildPseudoElement (bc, el.upgrade (), marker.unwrap ());
808+ }
809+ }
810+
805811 if (auto before = el ? el->getPseudoElement (Dom::PseudoElement::BEFORE ) : NONE ) {
806- _buildPseudoElement (bc, before.unwrap ());
812+ _buildPseudoElement (bc, el. upgrade (), before.unwrap ());
807813 }
808814
809815 for (auto child = parent->firstChild (); child; child = child->nextSibling ()) {
810816 _buildNode (bc, *child);
811817 }
812818
813819 if (auto after = el ? el->getPseudoElement (Dom::PseudoElement::AFTER ) : NONE ) {
814- _buildPseudoElement (bc, after.unwrap ());
820+ _buildPseudoElement (bc, el. upgrade (), after.unwrap ());
815821 }
816822}
817823
@@ -885,18 +891,56 @@ export Box _buildBlockPseudoElement(Rc<Dom::PseudoElement> el) {
885891static void _buildPseudoElement (BuilderContext bc, Rc<Dom::PseudoElement> pseudoElement) {
886892 auto style = pseudoElement->computedValues ();
887893 auto display = style->display ;
894+
888895 if (display == Display::NONE )
889896 return ;
890897
891- if (display == Display::INLINE or
892- display == Display::CONTENTS ) {
898+ bool isBeforeOrAfter = (pseudoElement->type == Dom::PseudoElement::BEFORE or pseudoElement->type == Dom::PseudoElement::AFTER );
899+ if (isBeforeOrAfter and (style->content .is <Keywords::Normal>() or style->content .is <Keywords::None>())) {
900+ return ;
901+ }
902+
903+ auto generateInnerContent = [&](BuilderContext& innerBc) {
904+ if (pseudoElement->type == Dom::PseudoElement::MARKER and style->content .is <Keywords::Normal>()) {
905+ String marker = " " s;
906+ auto listStyleType = originatingElement->specifiedValues ()->list ->type ;
907+ yap (" list style type: {}" , listStyleType);
908+ if (listStyleType == CustomIdent{" disc" _sym}) {
909+ marker = " \u2022 " s;
910+ } else if (listStyleType == CustomIdent{" circle" _sym}) {
911+ marker = " \u25E6 " s;
912+ } else if (listStyleType == CustomIdent{" square" _sym}) {
913+ marker = " \u25AA " s;
914+ } else if (listStyleType == CustomIdent{" decimal" _sym}) {
915+ marker = Io::format (" {}. " , originatingElement->counters .innerMost (CustomIdent{" list-item" _sym}).v1 );
916+ }
917+ _buildText (innerBc, marker.str (), style);
918+ } else if (style->content .is <String>()) {
919+ // TODO: Expand this to iterate over a Vector of content items (Strings, URLs, Counters)
920+ _buildText (innerBc, style->content .unwrap <String>().str (), style);
921+ }
922+ };
923+
924+ if (display == Display::INLINE or display == Display::CONTENTS ) {
893925 bc.startInlineBox (_proseStyleFromStyle (*style, style->fontFace ));
894- if (auto maybeStr = style->content .is <String>())
895- _buildText (bc, maybeStr->str (), style);
926+ generateInnerContent (bc);
896927 bc.endInlineBox ();
897928 } else {
898929 bc.flushRootInlineBoxIntoAnonymousBox ();
899- bc.addToParentBox (_buildBlockPseudoElement (pseudoElement));
930+
931+ Box pseudoBox = {style, pseudoElement->type }; // Ensure Box constructor accepts pseudo type
932+ InlineBox rootInlineBox{_proseStyleFromStyle (*style, style->fontFace )};
933+
934+ BuilderContext pseudoBc = (display == Display::Inside::FLEX )
935+ ? bc.toFlexContext (pseudoBox, rootInlineBox)
936+ : bc.toBlockContext (pseudoBox, rootInlineBox);
937+
938+ pseudoBc.startInlineBox (_proseStyleFromStyle (*style, style->fontFace ));
939+ generateInnerContent (pseudoBc);
940+ pseudoBc.endInlineBox ();
941+
942+ pseudoBc.finalizeParentBoxAndFlushInline ();
943+ bc.addToParentBox (std::move (pseudoBox));
900944 }
901945}
902946
@@ -947,22 +991,21 @@ export Box buildForPseudoElement(Rc<Dom::PseudoElement> el, usize currentPage, R
947991 auto prose = makeRc<Gfx::Prose>(proseStyle);
948992 prose->append (style->content .unwrap <String>().str ());
949993 return Box{style, InlineBox{prose}, el};
950- } else if (style->content .is <ElementContent >()) {
951- auto elt = style->content .unwrap <ElementContent >();
994+ } else if (style->content .is <ElementFunc >()) {
995+ auto elt = style->content .unwrap <ElementFunc >();
952996 if (auto infos = runningPos.match (elt, currentPage)) {
953997 Box box = buildElement (infos.unwrap ().element );
954998 box.style ->position = Keywords::STATIC ;
955999 return box;
9561000 }
957- } else if (auto elt = style->content .is <Counter>()) {
958- if (elt->type == Counter::Type::PAGE ) {
959- auto prose = makeRc<Gfx::Prose>(proseStyle);
960- prose->append (Io::toStr (currentPage + 1 ).str ());
961- return Box{style, InlineBox{prose}, el};
962- }
1001+ } else if (auto it = style->content .is <CounterFunc>()) {
1002+ auto prose = makeRc<Gfx::Prose>(proseStyle);
1003+ auto maybeCounter = el.counters .innerMost (it->name ).v0 ;
1004+ prose->append (" {}" _f (maybeCounter ? maybeCounter->value : 0 ).str ());
1005+ return {style, InlineBox{prose}, nullptr };
9631006 }
9641007
965- return {style, el };
1008+ return {style, nullptr };
9661009}
9671010
9681011} // namespace Vaev::Layout
0 commit comments