Skip to content
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

i want new paragraph(enter) not new lines(shift+enter) #25

Open
Sakarin23479 opened this issue Aug 5, 2022 · 4 comments
Open

i want new paragraph(enter) not new lines(shift+enter) #25

Sakarin23479 opened this issue Aug 5, 2022 · 4 comments

Comments

@Sakarin23479
Copy link

when add \n in text and then export to docx (\n = pic 1)
i'm use paragraph mark for see shift+enter or enter
but i need a enter not shift+enter
pic 1 shift+enter
image
pic 2 enter only
image

@Sakarin23479
Copy link
Author

@nguyenthenguyen pls help me

@NieR4ever
Copy link

@Sakarin23479 This is just a simple project for text replacement in DOCX files. If you want to handle the situation you mentioned, it would be necessary to process the content in XML format. It seems that the current project does not have this capability.

@hhhcj
Copy link

hhhcj commented Mar 4, 2024

It's difference between hardline and softline. Maybe this is what you need.

const TAB = "</w:t><w:tab/><w:t>"
const NEWLINE = "</w:t><w:br/><w:t>" //<w:p></w:p>
const HARDLINE = "</w:t><w:p></w:p><w:t>"

func encode(s string) (string, error) {
	var b bytes.Buffer
	enc := xml.NewEncoder(bufio.NewWriter(&b))
	if err := enc.Encode(s); err != nil {
		return s, err
	}
	output := strings.Replace(b.String(), "<string>", "", 1) // remove string tag
	output = strings.Replace(output, "</string>", "", 1)
	output = strings.Replace(output, "&#xD;&#xA;", NEWLINE, -1) // \r\n (Windows newline)
	output = strings.Replace(output, "&#xD;", NEWLINE, -1)      // \r (earlier Mac newline)
	output = strings.Replace(output, "&#xA;", NEWLINE, -1)      // \n (unix/linux/OS X newline)
	output = strings.Replace(output, "&#x1;", HARDLINE, -1)     // \n (unix/linux/OS X newline)
	output = strings.Replace(output, "&#x9;", TAB, -1)          // \t (tab)
	return output, nil
}

@hhhcj
Copy link

hhhcj commented Mar 4, 2024

I fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants