title_body: Problem with hyperlinks after converting chm to epub with calibre
upvoted_answer: CHM and epub are based on html files, but generally the production method for chm determines how simple the code is. Often the HTML files in the CHM files are made of complicated code which confuse calibre.  
  
  The first question to ask is: why do you want to convert it to epub? 1)Because you have one special file  you wish to read in that format or 2)eventually you want to republish (i.e., "repurpose") the content so that others can read it in an epub reader? or 3)you have many different chm files you wish to convert. 
  
  If you need it just for your reference, I would try skipping the step of converting to epub and just look for a chm reader on your device. Android and Ios have decent apps which can read chm files natively. That is always the best option. 
  
  I tried converting a simple chm to epub using calibre. Guess what? All the hyperlinks work for me. It sounds as if you are saying that the glossary for your chm contains all the definitions, and the problem is that every defined word goes to the top of the page (instead of going to the right part of the page).  My test files don't have anchors, so I cannot see what you are talking about. 
  
  To diagnose the problem, you need to view the source of the chm and epub. 
  
  The first step is renaming the epub to zip and then unzipping everything so you can see the html. Then open one of the files in a text editor (or open it in a browser, right click and select VIEW SOURCE). 
  
  You can also view source in a chm file on Windows. Just right click on the topic with a defective hyperlink, view the hyperlink and see what is supposed to happen. 
  
  From doing these two steps (and especially the first), you can see why the hyperlinks in the epub are not working. Perhaps epub stripped the part of the hyperlink that would put the target hyperlink to the middle of the page. 
  Normally it should look like this &lt;a href="first.html#elephant"&gt; where "elephant" refers to the anchor in the middle of the page. 
  
  Another possible cause of the problem is that the chm file might be doing weird stuff. Perhaps, depending on the authoring tool which produced the chm file, javascript is making the anchor (I'm guessing randomly here). 
  
  Another possibility is that when producing the epub file from chm, for some reason calibre removed the anchor references. If the glossary page does not have something like: 
  
  &lt;h2 id="elephant"&gt; or &lt;a id="elephant"&gt;
  
  
  it will be impossible for the hyperlink to find the anchor on that file. 
  
  Calibre gives you powerful tools (like regular expressions) to rewrite certain code when converting. (although it may take you a while to learn how). If you are motivated, you can probably just re-edit the html files and make sure the references work and then rezip it again and rename the file extension to epub.  
  
  Again, without seeing the HTML source, it's hard to know where the problem lies.  But again, finding an chm reader to read the file natively would probably be the easiest thing to do.