DevToys-app / DevToysMac

DevToys For mac
MIT License
9.2k stars 354 forks source link

Add hyphenation remover #9

Closed meokz closed 2 years ago

meokz commented 2 years ago

Hey, I implemented a hyphenation remover that removes unnecessary hyphenation from copied text from PDF. It is useful for preprocessing for translating English to other languages using Google Translate and DeepL. This is inspired by shaper (Ref: https://twitter.com/KeijiKobara/status/1391317599850430467?s=20&t=tb8xyWdcpLVKmAk99NNvMw)

Feel free to accept or decline this PR for reason that this is your personal project.

スクリーンショット 2022-02-04 18 09 03

ObuchiYuki commented 2 years ago

I also need to remove hyphenation when pasting into Deepl or Google Translate, and I feel the need for this tool. Therefore, I would like to incorporate this PR. As for the UI implementation, it's done perfectly!

However, in the implementation below, doesn't it replace all " " in the original sentence?

private func getFormattedText(_ input: String) -> String {
    let lines = input
        .components(separatedBy: .newlines)
        .map { $0.replacingOccurrences(of: "- ", with: "") }
    let output = lines
        .joined(separator: " ")
        .replacingOccurrences(of: "  ", with: "\n")
    return output
}

If this is not a problem, please comment.

meokz commented 2 years ago

I think we don't need to worry about it. A single space in the original sentence will be preserved correctly.

Note that if there are two or more consecutive spaces in the original sentence, there is a mistake that will be replaced by a new line.

ObuchiYuki commented 2 years ago

@meokz Sorry for the late reply. I see you said it's not a problem, so I'll merge it! Thanks for the new feature!