-
-
Notifications
You must be signed in to change notification settings - Fork 101
Implement Heading Styles (H1-H6) #589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DevinDuricka
wants to merge
33
commits into
MohamedRejeb:main
Choose a base branch
from
DevinDuricka:integrating-headings-into-old-code
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Implement Heading Styles (H1-H6) #589
DevinDuricka
wants to merge
33
commits into
MohamedRejeb:main
from
DevinDuricka:integrating-headings-into-old-code
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…sion between the M3 textstyles to their Heading equivalent. Also added some rudimentary initial toggle functionality.
…aph or selection paragraph(s) all either set the HeadingParagraphStyle or remove the HeadingParagraphStyle. Still todo: change some naming to heading from header, rename the primary function, alter the HTML conversion to use the HeadingParagraphStyle instead of the custom spanstyle, add unit tests.
…d also added the markdown values as a property for the HeadingParagraphStyle enum
…lookup the markdown # signs using the HeadingParagraphStyle function.
… encode the markdown since the tests were failing without it
…l need to add the paragraphstyle to the RichText encoded because the linespacing is different than default for typography
…with the HeadingParagraphStyle helper functions
… the HTML and Markdown Heading Tags.
…sParagraphStyle.kt to hold a reference to the ParagraphStyle (if applicable)
…sts, not just for the headings. I added logic to merge in the ParagraphStyle if it is found in the encoding map for either the Markdown or HTML. I also removed the sets of headings, since they ended up being unnecessary.
…tyle] applied to the paragraph. In Rich Text editors like Google Docs, heading styles (H1-H6) are applied to the entire paragraph. This function reflects that behavior by checking all child [RichSpan]s for a non-default [HeadingParagraphStyle]. If any child [RichSpan] has a heading style (other than [HeadingParagraphStyle.Normal]), this function returns that heading style, indicating that the entire paragraph is styled as a heading.
… the input ParagraphStyle
…was defaulting to <p> tags. Switching the ParagraphType to the RichParagraph allows us to also get the HeadingParagraphStyle.html, and still get the type to determine if it is <ul> or <ol>
…is was defaulting to <p> anytime the paragraphGroupTagName was not "ul" or "ol".
…raphy class. This will allow us to remove any inherited ParagraphStyle properties, but keep the user added ones. <h1> to <h6> tags will allow the browser to apply the default heading styles. If the paragraphTagName isn't a h1-h6 tag, it will revert to the old behavior of applying whatever paragraphstyle is present.
…ng the SpanStyle to the Css span style. If it is a heading paragraph style, remove the Heading-specific [SpanStyle] features via [unmerge] but retain the non-heading associated [SpanStyle] properties.
…ng the SpanStyle to the Css span style. If it is a heading paragraph style, remove the Heading-specific [SpanStyle] features via [unmerge] but retain the non-heading associated [SpanStyle] properties.
…to subsequent paragraphs. TODO - Verify that this isn't crucial (all the tests still pass)
…ill wasn't being removed.
… with the private add and remove heading paragraph style functions.
…Span or Paragraph style from the extended one. This is useful for removing the Heading's Span or Paragraph style when converting to HTML. Otherwise, it would encode the Heading Paragraph or Span style properties into the css of the HTML.
…the RichParagraph as the HeadingStyle gets set on the whole paragraph, not just a selection. The RichTextState now calls the setHeadingStyle on all the pertinent paragraphs.
…the RichParagraph as the HeadingStyle gets set on the whole paragraph, not just a selection. The RichTextState now calls the setHeadingStyle on all the pertinent paragraphs.
…ding span styles.
…eadingParagraphStyle and converting to/from html and Markdown
…ust the normal font weight and it conflicts if the user has a bold fontweight.
…kes more sense and avoid confusions with the ParagraphStyle
…ociated TextStyle for non-compose-richeditor composables, you need to be able to access it i.e. set a standard Text(style = getTextStyle())
Thanks for your contribution! I'm checking your PR. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implement Heading Styles (H1-H6)
This pull request introduces support for applying and managing heading styles (H1 through H6) as paragraph-level formatting within the Rich Editor. This is a common feature in rich text editors (like Google Docs) and improves the semantic representation of content when converting to formats like HTML and Markdown.
Key Features Implemented:
RichTextState.setHeadingStyle(style: HeadingStyle)
is added to allow users to apply or remove heading styles based on the current selection.HeadingStyle
enum is introduced to represent the different heading levels (Normal, H1-H6) and their associated Markdown elements and HTML tags.RichParagraph
to handle applying and removing heading-specificSpanStyle
andParagraphStyle
.diff
andunmerge
logic forSpanStyle
and adjusting how base headingSpanStyle
is retrieved (HeadingStyle.getSpanStyle
now returnsfontWeight = null
).RichTextStateHtmlParser.encode
): HTML heading tags (<h1>
-<h6>
) are correctly parsed into paragraphs with the correspondingHeadingStyle
and baseSpanStyle
/ParagraphStyle
. Inline styles within heading tags are merged with the base styles.RichTextStateHtmlParser.decode
):RichTextState
paragraphs withHeadingStyle
are correctly converted back to HTML using the appropriate<h1>
-<h6>
tags. User-applied additional inline styles (those not part of the base heading style) are included in thestyle
attribute of an inner<span>
tag using thediff
logic.RichTextStateMarkdownParser.encode
): Markdown heading syntax (#
,##
, etc.) is correctly parsed into paragraphs with the correspondingHeadingStyle
.RichTextStateMarkdownParser.decode
):RichTextState
paragraphs withHeadingStyle
are correctly converted back to Markdown using the appropriate#
syntax.HeadingStyle
functions and the encoding/decoding processes for both HTML and Markdown, including scenarios with additional inline styles.Closes #578