TextToHtml.bat - Easily create World Wide Web pages!

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Aacini
Expert
Posts: 1670
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: TextToHtml.bat - Easily create World Wide Web pages!

#31 Post by Aacini » 28 Mar 2014 15:59

aGerman wrote:As I already wrote UTF-8 could be the default setting for a certain text editor. Also it could happen that the encoding of text files were automatically changed during upload or download (depending on the target operating system of the server or even the client).

Regards
aGerman

Yes, I understand that; however, I think the encoding does not apply in this case because the files are copied with a select-text, copy-paste operation:

ReadMeFirst.txt file wrote:Follow these steps to download the files to your computer:

1. Right-click on destination folder, select New -> Text Document and enter the appropriate name from previous list (including the extension for .bat file); then open the new file (for .bat file, right-click on it and select Edit).
2. Open the corresponding file in this site (with "T2H - " prefix), select RAW below the file name, select all the text (Ctrl-A) and copy it (Ctrl-C). Close the window.
3. Select the file in your computer, paste the text (Ctrl-V) and close the file.
4. Repeat previous steps for all files.

If I create a file this way (that is the same way I create every new Batch file anyway) I think there is no way that the file change its type to UTF-8 for the fact of paste a block of text from the clipboard, unless that the text copied to the clipboard also includes its encoding...

Antonio

aGerman
Expert
Posts: 3971
Joined: 22 Jan 2010 18:01
Location: Germany

Re: TextToHtml.bat - Easily create World Wide Web pages!

#32 Post by aGerman » 28 Mar 2014 16:24

Firstly: the Windows clipboard automatically determines and changes the encoding of text depending on the target encoding of the involved program windows. This way you can copy e.g. a file name out of the Explorer window (which is Unicode encoded) and paste it into any text field window of another program. You don't have to take care what encoding the different windows support (mostly you will not know it) as long as both windows support the copied or pasted characters.

Secondly: the encoding of the saved text file may not have anything to do with the encoding of the window where you pasted the text. You can easily find it if you use the Windows editor (notepad.exe). The window where the text is displayed is always the same. But if you use the "Save As" dialogue you can choose one of 4 different encodings to save the file.

Regards
aGerman

Aacini
Expert
Posts: 1670
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: TextToHtml.bat - Easily create World Wide Web pages!

#33 Post by Aacini » 28 Mar 2014 17:51

@aGerman:

Precisely: based on the standard behavior you described, I am very interested in know what is the difference that caused that I got a certain result, but at least two users (foxidrive and Matt Williamson) got a different result from the same procedure. In my computer a Right-click, New -> Text Document invoke the standard Windows editor (notepad.exe); the paste operation (Ctrl-V) place in the notepad window the same raw text I just copied from the original site, and closing the window (and saving the file) does not change the original notepad encoding (Ansi).

I suppose that both foxi and Matt know that the purpose of this procedure is to create standard .bat and .txt files, so if the standard editor installed in their computers is a different one (one that does not create Ansi encoded files), they should use a standard editor instead. Also, I suppose that they have not any reason to use "Save As" dialog and select UTF-8 encoding for the new files!

The bottom line is this: independently of the series of factors that may produce text files with different encodings, Why the same procedure produce differently encoded files for different users? If I not find the explanation to this point, it will continue happening to other users!

Antonio

aGerman
Expert
Posts: 3971
Joined: 22 Jan 2010 18:01
Location: Germany

Re: TextToHtml.bat - Easily create World Wide Web pages!

#34 Post by aGerman » 28 Mar 2014 18:10

I think we have to wait for Matt to conclusively clarify these issues.
But it's not too difficult to change the defaults. On my computer text files open in PSPad. The same way I changed the "Edit" context menu for *.bat files and some other script file types. All you have to do is either change the registry values by hand or (in case the program offers this possibility) select the file types that should open with the new editor during the installation or in the program settings :wink:

Regards
aGerman

penpen
Expert
Posts: 1864
Joined: 23 Jun 2013 06:15
Location: Germany

Re: TextToHtml.bat - Easily create World Wide Web pages!

#35 Post by penpen » 28 Mar 2014 18:45

I've noticed some redirections to a file, without ensuring a specific character encoding choosen: This may result in problems (I haven't read this thread fully, so i don't know, if this causes the issue).

You may initialize a batch file to use ANSI per default starting with:

Code: Select all

@echo off
if not "%~1" == "initialized" (
   cmd /A /C %~dpnx0 "initialized" %*
   goto :eof
)
:: main code


penpen

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: TextToHtml.bat - Easily create World Wide Web pages!

#36 Post by Liviu » 28 Mar 2014 18:53

Aacini wrote:I am very interested in know what is the difference that caused that I got a certain result, but at least two users (foxidrive and Matt Williamson) got a different result from the same procedure.
I guess the difference must be in the procedure. It's fairly easy to mix/mess up encodings by accident. As aGerman said, we'll have to wait and see, but I seriously doubt that the same steps under similar configurations would cause different outputs between you and the others.

Aacini wrote:In my computer a Right-click, New -> Text Document invoke the standard Windows editor (notepad.exe); the paste operation (Ctrl-V) place in the notepad window the same raw text I just copied from the original site
This is in fact more complicated, like all things supposed to be "transparent" ;-) and the outcome depends on both what program you copy from, and where you paste into. Normally, the browser would copy the text to the clipboard as Unicode, and the text editor would paste it as Unicode then convert it to a target encoding when saving the file. However, that's up to the respective programs and not enforced by Windows - and there are other 8-bit text clipboard formats available, including ANSI or OEM encodings, with various automatic conversions between them. This is already pretty far removed from batch matters per se, but you can inspect the clipboard mechanics with http://www.nirsoft.net/utils/inside_clipboard.html and check the default format conversions at http://msdn.microsoft.com/en-us/library/windows/desktop/ms649013(v=vs.85).aspx#_win32_Synthesized_Clipboard_Formats.

Aacini wrote:and closing the window (and saving the file) does not change the original notepad encoding (Ansi).
That's correct as long as the text you paste is "losslessly" translatable to the default ANSI codepage set on your computer. Otherwise, notepad will prompt "This file contains characters in Unicode format which will be lost if you save this file as an ANSI encoded text file. To keep the Unicode information, click Cancel below and then select one of the Unicode options from the Encoding drop down list. Continue?" - and this behavior goes back to at least XP.

Liviu

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: TextToHtml.bat - Easily create World Wide Web pages!

#37 Post by foxidrive » 28 Mar 2014 19:17

Aacini wrote:Hey! I just downloaded again TextToHtml.bat file from the original site:

Code: Select all

28/03/2014  10:23 a. m.            47,500 TextToHtml.bat

but the listing of Matt Williamson show that his file have 60 bytes more!!!

Code: Select all

12/10/2013  06:06 PM            47,560 texttohtml.bat


I just downloaded it again from your link in this post and it is 47,560 bytes.

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: TextToHtml.bat - Easily create World Wide Web pages!

#38 Post by Liviu » 28 Mar 2014 20:19

foxidrive wrote:I just downloaded it again from your link in this post and it is 47,560 bytes.

I get 47,560 as well if I click the DOWNLOAD button, but that saves the file as UTF-8 (without BOM). Guess it must have something to do with pastebin's identification of the file type and/or encoding in the download script, I don't know - and it might depend on the browser, too.

But if click the RAW button, instead, then Ctrl-A select all, paste into notepad and save-as ANSI, then I get the ANSI encoded 47,500 bytes file. Or, if I click inside the "paste raw" box at the bottom, select all, and repeat the paste above, I get a 47,498 bytes file which is the same as the previous one except it's missing the CR+LF at the very end.

Liviu

Aacini
Expert
Posts: 1670
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: TextToHtml.bat - Easily create World Wide Web pages!

#39 Post by Aacini » 28 Mar 2014 22:50

Liviu wrote:
foxidrive wrote:I just downloaded it again from your link in this post and it is 47,560 bytes.

I get 47,560 as well if I click the DOWNLOAD button, but that saves the file as UTF-8 (without BOM). Guess it must have something to do with pastebin's identification of the file type and/or encoding in the download script, I don't know - and it might depend on the browser, too.

But if click the RAW button, instead, then Ctrl-A select all, paste into notepad and save-as ANSI, then I get the ANSI encoded 47,500 bytes file. Or, if I click inside the "paste raw" box at the bottom, select all, and repeat the paste above, I get a 47,498 bytes file which is the same as the previous one except it's missing the CR+LF at the very end.

Liviu

Thanks A LOT, Liviu!!! :D


Wow! I just confirmed that there are 3 ways to download the files from the original site that produce 3 different result files, although the last 2 just differ in the last CR+LF. This would be a serious problem if would not be instructions at this respect. However, in my opinion the instructions given in the ReadMeFirst.txt file are clear enough...

An entirely different problem is when the users choose to ignore the instructions. In this case, like in many other cases of application programs (or even any other system/appliance/whatever other thing complex enough to require an instruction manual), the users just don't get the desired results. However, this personal problem may become a serious one if the users fooled about this point:

In reply #13 Aacini wrote:I just made a test with the files on that site. This is what I did:

• Read the ReadMeFirst.txt file
• I downloaded the files following the instructions of the ReadMeFirst.txt file: after open each file, select RAW, then press Ctrl-A, Ctrl-C and close it, then select the destination file and Ctrl-V. Although the procedure is a little cumbersome, I downloaded all 10 files in about 8 minutes...

Antonio
In the next reply, foxidrive wrote:
Aacini wrote:I just made a test with the files on that site. This is what I did:

Although the procedure is a little cumbersome


Yes, it is. I did the same thing. It doesn't work.


In this case the developer is fooled about a supposed bug in the program that really don't exists! :? :evil:

Antonio

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: TextToHtml.bat - Easily create World Wide Web pages!

#40 Post by foxidrive » 28 Mar 2014 23:24

Aacini wrote:An entirely different problem is when the users choose to ignore the instructions.

Antonio


Antonio,

A problem is really that you force your users to jump through hoops - why?
I've suggested to you more than once in the past that you should provide a single ZIP to download, for this project and your other projects.


You must be aware that there are thousands of users who ask questions and whose skills are limited - yet you make people cut and paste different bits of text to decode your binaries,
and errors will often creep in. Why don't you consider your users and make it easy to get these things in a way that can't fail? A ZIP file. Dropbox. Or another host.

In this case it's the pastebin site that causes issues.

IDK. Maybe you think you're teaching people to do stuff, but you're actually making it difficult and a large percentage of people will never try to use your tools.

You're skilled at your code - but you could also make it easy for people to try your tools.


Aacini wrote:In this case the developer is fooled about a supposed bug in the program that really don't exists! :? :evil:


In this case two skilled people failed because the pastebin site is flawed. It is quite reasonable to expect that the download button retrieves the file correctly.

How many other people failed, and didn't tell you about it? You will notice that there were no comments in this thread regarding this tool.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: TextToHtml.bat - Easily create World Wide Web pages!

#41 Post by Dos_Probie » 29 Mar 2014 03:39

+1 Foxidrive, Just Zip then dropbox it or use free cloud service like https://www.copy.com/home/ that you can just drag and drop the zip file to.

aGerman
Expert
Posts: 3971
Joined: 22 Jan 2010 18:01
Location: Germany

Re: TextToHtml.bat - Easily create World Wide Web pages!

#42 Post by aGerman » 29 Mar 2014 05:50

you should provide a single ZIP to download

Full ACK. For code that is critical to copy or download you have to make sure the user is not able to fail at this point. Otherwise everything that could happen will happen. The only question is when. (And then you waste hours to figure out why, you despair to find failures that actually don't exist and eventually you destroy your forum thread by discussing off topic issues :roll:)

Regards
aGerman

Matt Williamson
Posts: 78
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Re: TextToHtml.bat - Easily create World Wide Web pages!

#43 Post by Matt Williamson » 31 Mar 2014 06:03

Ok, I got it working. It was the encoding that threw it off. I use Notepad++ and the default encoding type is UTF-8 without BOM. Once I changed it to ansi and re-did all of the steps in the readme, it worked flawlessly. In my opinion though, this is to many variables. Foxi's comment about a .zip file get's a thumbs up from me. That way, you control the encoding and any other variables that could be introduced.

Another suggestion, When I ran the HelptoTextToHTML.bat file it got to a point where it just seemed to hang. I read through it and saw that it created a couple of temp files so I could see it was still working based upon the file size increasing but a simple spinner in that spot would be a good idea. It took a good 2-3 minutes and I'm on an 3.4ghz quad core machine with 8 gigs of ram. A typical user would probably just kill the window, thinking something hung. I was about to before I decided to read the code and saw the temp file.

Ok, now that that is out of the way. This is some amazing code Antonio! The deeper I get into it, the more amazed I get. Good Work!

Direct link to the files Aascini HTML Tools

Post Reply