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

Fix the height issue of the img tags #70

Merged
merged 4 commits into from
Dec 5, 2014
Merged

Fix the height issue of the img tags #70

merged 4 commits into from
Dec 5, 2014

Conversation

zsxwing
Copy link
Member

@zsxwing zsxwing commented Dec 2, 2014

Fix #69.

docs

The new img tags are generated by the following codes:

import java.io.File
import java.net.URL
import javax.swing.ImageIcon

import scala.io._
import scala.collection.mutable

object Main {

  def imageMeta(imgURL: String): (Int, Int) = {
    val imageIcon = new ImageIcon(new URL(imgURL))
    (imageIcon.getIconWidth(), imageIcon.getIconHeight())
  }

  def clearImg(file: String): Unit = {

    val img = """<img.*src="(.*?)".*>""".r

    val urlImgCache = mutable.Map[String, String]()

    for (line <- Source.fromFile(new File(file))(Codec.UTF8).getLines()) {
      val newLine = img.findFirstMatchIn(line) map {
        imgTag => {
          val tagContent = imgTag group 0
          val url = imgTag group 1
          val newImgTag = if (urlImgCache.contains(url)) {
            urlImgCache(url)
          } else {
            val (width, height) = imageMeta(url)
            val ratio = 640.0 / width
            val scaleHeight = (height * ratio).toInt
            val newImgTag = s"""<img width="640" height="${scaleHeight}" src="${url}" alt="" />"""
            urlImgCache += url -> newImgTag
            newImgTag
          }
          line.replace(tagContent, newImgTag)
        }
      } getOrElse (line)
      println(newLine)
    }
  }

  def main(args: Array[String]): Unit = {
    clearImg("/home/zsx/workspace/RxScala/src/main/scala/rx/lang/scala/Observable.scala")
  }
}

@samuelgruetter
Copy link
Collaborator

Did you check if the html generated by scaladoc still looks ok? Just to be sure...

Conflicts:
	src/main/scala/rx/lang/scala/Observable.scala
@zsxwing
Copy link
Member Author

zsxwing commented Dec 4, 2014

Did you check if the html generated by scaladoc still looks ok? Just to be sure...

Yes. I also realized the links are still old although they can redirect to the correct address, such as https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/toMap.png. I'm working on updating them.

@zsxwing
Copy link
Member Author

zsxwing commented Dec 5, 2014

I published the new Scaladoc of this PR here: http://code.iamzsx.me/RxScala/#package

@samuelgruetter
Copy link
Collaborator

LGTM, thanks :)

zsxwing added a commit that referenced this pull request Dec 5, 2014
Fix the height issue of the img tags
@zsxwing zsxwing merged commit cb73e3c into ReactiveX:0.x Dec 5, 2014
@zsxwing zsxwing deleted the img branch December 5, 2014 08:19
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.

Lack of height attributes for images in scaladocs displays poorly in IntelliJ/IDEA
2 participants