question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Character style 'strong' for TextRun

See original GitHub issue

image

I have a paragraph block which has two TextRuns in it, for example:

new Paragraph ({
    children: [
        new TextRun({
            text: "First Word",
            bold: true
        }),
        new TextRun(" - This text was created using heading 3 paragraph style. It has a slight left indentation for lines except the first one.")
    ]
})

Currently I am using the bold parameter but I want to use the “strong” character style. This is because styles can be manipulated from Design > Quick Parts > Field. Any way to do this?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dolanmiucommented, Dec 24, 2020

in 5.5.0 in the next release

maybe in a few weeks time

0reactions
deathg0dcommented, Mar 17, 2021

That’s difficult to implement because last element of the array may not be the last element of the page. On every page, headers should reflect word heading of that particular page only. If you download and check the doc file I previously posted you’ll notice that the headers are dynamic. They are different for every page and only correspond to words in that particular page.

Word provides this feature. To place dynamic components like these in word, I can simply go to Design > Quick Parts > Field >> StyleRef > strong. This will automatically select the first strong styled phrase of the page (there’s another option to select last strong styled phrase as well).

However, StyleRef requires paragraph or header styles. But bold is not a style and hence is not selectable. We need a strong style, which is the reason for this thread.

In the word file I posted, you’ll find that the paragraph style is Normal but the first word has character style strong. This is why I am able to create the dynamic headers.

With docx plugin, I am not able to set character style to strong. I created a docx file using version 5.5.0 and the following code for the first word from here:

new TextRun({
    text: 'word1',
    style: "strong"
})

Once the doc is created, If i select the word and check the style, it still shows Normal not Strong. If I can set character style to Strong that would solve first part of the problem for now at least.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Editing and styling text | Apps Script - Google Developers
A text run is a segment of text where all the characters have the same text style. Text styling. Text style determines the...
Read more >
Retain italics & bold using paragraph styles
The italics and bold etc. don't have a character style - that's why when you apply the paragraph style it overrides the italics...
Read more >
Text-related objects — python-docx 0.8.11 documentation
Append a run to this paragraph containing text and having character style identified by style ID style. text can contain tab ( \t...
Read more >
How can I create a character style so that it will only have a
In an interesting thread I just read about character styles, Suzanne S. Barnhill ... Those are the Strong and Emphasis character styles.
Read more >
docx/styling-with-js.md at master · dolanmiu/docx - GitHub
Characters : Attributes that can change within a paragraph. e.g., bold, italics, etc. Paragraphs: Attributes like indent, text alignment, line spacing, etc.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found