TypeScript-Handbook icon indicating copy to clipboard operation
TypeScript-Handbook copied to clipboard

As a reader, I would like this handbook in epub format

Open dac514 opened this issue 9 years ago • 8 comments

Can you make this book available in Epub (or mobi) format?

dac514 avatar Sep 01 '16 14:09 dac514

Sorry for the delay. I've definitely wanted this in the past. You can definitely do this on your own using Pandoc or Gitbook. I think we'd accept PRs on this as well.

DanielRosenwasser avatar Sep 27 '16 15:09 DanielRosenwasser

Can I work on this if its not already taken? I am trying to do gitbook, will update if it goes well!

vgvenkat avatar Oct 27 '16 18:10 vgvenkat

Just saw this, but sure, go for it!

DanielRosenwasser avatar Nov 11 '16 21:11 DanielRosenwasser

Just wrote a Ruby script to do this using pandoc, see below. Let me know if you'd like to have this as a PR in some way.

# Define chapters

chapters = [
  "Basic Types",
  "Variable Declarations",
  "Interfaces",
  "Classes",
  "Functions",
  "Generics",
  "Enums",
  "Type Inference",
  "Type Compatibility",
  "Advanced Types",
  "Symbols",
  "Iterators and Generators",
  "Modules",
  "Namespaces",
  "Namespaces and Modules",
  "Module Resolution",
  "Declaration Merging",
  "JSX",
  "Decorators",
  "Mixins",
  "Triple-Slash Directives",
  "Type Checking JavaScript Files"
]


# Reformat Markdown sources

full_content = <<-HEREDOC
---
title: TypeScript Handbook
author: Microsoft Corporation
rights: Apache License 2.0
language: en-US
---
HEREDOC

chapters.each do |chapter|
  file_name = "#{chapter}.md"
  content = File.read(file_name)

  # Increase section level of headings
  content = content.gsub(/(#){1,5}\s([^\n]*)/, '#\1 \2')

  # Add top-level heading
  content = content.prepend("# #{chapter}\n\n")

  full_content << content
end

File.write("all.md", full_content)

# Generate epub file

system("pandoc -s -o ~/Desktop/TypeScript-Handbook.epub all.md")

File.delete("all.md")

olavolav avatar Jul 30 '18 17:07 olavolav

@DanielRosenwasser Could you clarify what kind of PRs you'd welcome on this issue? I suppose for example one could rewrite the Ruby script as Typescript, and then perhaps move this to a new scripts folder.

What do you think?

olavolav avatar Aug 06 '18 11:08 olavolav

hay!

I got my epub copy by using gitbook.

here the step:

ensure you had gitbook installed

  1. git clone this repo

  2. add SUMMARY.md to root dir.

# SUMMARY

* [tutorials](TypeScript in 5 minutes)
  * [TypeScript in 5 minutes](pages\tutorials\TypeScript in 5 minutes.md)
  * [ASP.NET Core](pages\tutorials\ASP.NET Core.md)
  * [Gulp](pages\tutorials\Gulp.md)
  * [Migrating from JavaScript](pages\tutorials\Migrating from JavaScript.md)
  * [React & Webpack](pages\tutorials\React & Webpack.md)
* [declaration files](Introduction)
  * [Introduction](pages\declaration files\Introduction.md)
  * [Library Structures](pages\declaration files\Library Structures.md)
  * [By Example](pages\declaration files\By Example.md)
  * [Do's and Don'ts](pages\declaration files\Do's and Don'ts.md)
  * [Deep Dive](pages\declaration files\Deep Dive.md)
  * [Templates](pages\declaration files\Templates.md)
  * [Publishing](pages\declaration files\Publishing.md)
  * [Consumption](pages\declaration files\Consumption.md)
* [handbook](Basic Types)
  * [Basic Types](pages\Basic Types.md)
  * [Variable Declarations](pages\Variable Declarations.md)
  * [Interfaces](pages\Interfaces.md)
  * [Classes](pages\Classes.md)
  * [Functions](pages\Functions.md)
  * [Generics](pages\Generics.md)
  * [Enums](pages\Enums.md)
  * [Type Inference](pages\Type Inference.md)
  * [Type Compatibility](pages\Type Compatibility.md)
  * [Advanced Types](pages\Advanced Types.md)
  * [Symbols](pages\Symbols.md)
  * [Iterators and Generators](pages\Iterators and Generators.md)
  * [Modules](pages\Modules.md)
  * [Namespaces](pages\Namespaces.md)
  * [Namespaces and Modules](pages\Namespaces and Modules.md)
  * [Module Resolution](pages\Module Resolution.md)
  * [Declaration Merging](pages\Declaration Merging.md)
  * [JSX](pages\JSX.md)
  * [Decorators](pages\Decorators.md)
  * [Mixins](pages\Mixins.md)
  * [Triple-Slash Directives](pages\Triple-Slash Directives.md)
  * [Type Checking JavaScript Files](pages\Type Checking JavaScript Files.md)

I generate this markdown by running a js script here:

const fs = require('fs')
const path = require('path')

const files = {
  'tutorials': [
    'TypeScript in 5 minutes',
    'ASP.NET Core',
    'Gulp',
    'Migrating from JavaScript',
    'React & Webpack'
  ],
  'declaration files': [
    'Introduction',
    'Library Structures',
    'By Example',
    'Do\'s and Don\'ts',
    'Deep Dive',
    'Templates',
    'Publishing',
    'Consumption',

  ],
  'handbook': [
    'Basic Types',
    'Variable Declarations',
    'Interfaces',
    'Classes',
    'Functions',
    'Generics',
    'Enums',
    'Type Inference',
    'Type Compatibility',
    'Advanced Types',
    'Symbols',
    'Iterators and Generators',
    'Modules',
    'Namespaces',
    'Namespaces and Modules',
    'Module Resolution',
    'Declaration Merging',
    'JSX',
    'Decorators',
    'Mixins',
    'Triple-Slash Directives',
    'Type Checking JavaScript Files'
  ]
}

let summaryContent = '# SUMMARY\n\n' 

for (let section in files) {
  summaryContent += `* [${section}](${files[section][0]})\n`
  summaryContent += files[section].map(file => {
    if(section == 'handbook') section = ''
    resolvedPath = path.join('pages',section, file + '.md')
    if (fs.existsSync(resolvedPath)) {
      return `  * [${file}](${resolvedPath})`
    }
    return ''
  }).join('\n') + '\n'
  
}
fs.writeFileSync('./SUMMARY.md', summaryContent)
  1. last run
gitbook epub . typescript-handbook.epub

You also can get a copy of pdf/mobi.

yidafu avatar Dec 01 '18 04:12 yidafu

Thanks for the code, before generating the book i needed to:

Save the nodejs/js code in a file called crea-sumary.js and run:

node crea-sumary.js

then install gitbook and a dependency:

npm install gitbook-cli -g npm install svgexport -g

and finally generate the epub:

gitbook epub . typescript-handbook.epub

hanspoo avatar Jun 07 '20 17:06 hanspoo

We ship a copy of the handbook with epub and pdf support now - http://www.staging-typescript.org/docs/handbook/

orta avatar Jun 08 '20 19:06 orta