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

add flag to specify which line feed to use #3567

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Hew-ux
Copy link

@Hew-ux Hew-ux commented Dec 21, 2021

... for downloadable code blocks.

This is more a feature request than it is a pull request, but I've done it like this to easily show/allow others to modify the code. Underneath my changes, at line 34, I've put in a commented out alternative version, primarily to demonstrate an alternative approach.

I've been using Dokuwiki for a while to create and provide scripts for novice users to download and use for a small custom distribution based on Linux we are building that is typically deployed and edited on a remote network connection, using another computer to make those edits. This all works wonderfully well when downloading the files in a strictly Linux environment, however I've found out that users of Windows computers (which I've found out, is most of my reader's primary OS) were receiving these files with the incorrect CRLF line terminators. Looking through the web I found #863 , a change made around six years ago making DokuWiki automatically detect and change the line feed used in the downloaded file depending on the user's operating system. The actual commit merged that fixed it is #872 .

This is a neat feature, and I wouldn't want to undo that behaviour by default, but I would like to add a flag that editors can use to specify "hey, this is a Unix script, and the linefeeds need to remain untouched", so that neophyte users can simply download and use the script files as they are without having to do additional line feed conversions.

I'm aware that I'm changing the number of arguments that this function accepts, and that this would cause issues elsewhere, that's precisely why I'm asking for assistance here! I'm not a veteran DokuWiki coder, so please feel free to completely change this code, or close this pull request if it can be implemented in a much better way. The original PR I'm seeing that changed this behaviour in the first place only edited this file, so I'm not even sure where to begin looking for other files that might be calling this one, if there are any at all.

... for downloadable code blocks.

This is more a feature request than it is a pull request, but I've done it like this to easily show/allow others to modify the code. Underneath my changes, at line 34, I've put in a commented out alternative version, primarily to demonstrate an alternative approach.

I've been using Dokuwiki for a while to create and provide scripts for novice users to download and use for a small custom distribution based on Linux we are building that is typically deployed and edited on a remote network connection, using another computer to make those edits. This all works wonderfully well when downloading the files in a strictly Linux environment, however I've found out that users of Windows computers (which I've found out, is most of my reader's primary OS) were receiving these files with the incorrect CRLF line terminators. Looking through the web I found dokuwiki#863 , a change made around six years ago making DokuWiki automatically detect and change the line feed used in the downloaded file depending on the user's operating system. The actual commit merged that fixed it is dokuwiki#872 .

This is a neat feature, and I wouldn't want to undo that behaviour by default, but I would like to add a flag that editors can use to specify "hey, this is a Unix script, and the linefeeds need to remain untouched", so that neophyte users can simply download and use the script files as they are without having to do additional line feed conversions.

I'm aware that I'm changing the number of arguments that this function accepts, and that this would cause issues elsewhere, that's precisely why I'm asking for assistance here! I'm not a veteran DokuWiki coder, so please feel free to completely change this code, or close this pull request if it can be implemented in a much better way. The original PR I'm seeing that changed this behaviour in the first place only edited this file, so I'm not even sure where to begin looking for other files that might be calling this one, if there are any at all.
@Klap-in
Copy link
Collaborator

Klap-in commented Dec 21, 2021

Is there overlap with this and the highlighting options: https://www.dokuwiki.org/syntax_highlighting
#2307

@@ -25,10 +25,16 @@ public function code($text, $language = null, $filename = '') {
$filename = \dokuwiki\Utf8\Clean::stripspecials($filename, '_');

// send CRLF to Windows clients
if(strpos($INPUT->server->str('HTTP_USER_AGENT'), 'Windows') !== false) {
$text = str_replace("\n", "\r\n", $text);
if(strpos($INPUT->server->str('HTTP_USER_AGENT'), 'Windows') !== false && $linefeed !== "Unix") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess $linefeed is not defined.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved, the function now has the linefeed as an argument and it defaults to ''

with a default value to avoid "not defined" situations
@Hew-ux
Copy link
Author

Hew-ux commented Dec 21, 2021

I don't really know how to fix the "overlap" thing you've mentioned. Where is that part coded in #2307 ?

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

Successfully merging this pull request may close these issues.

None yet

2 participants